8 AnswersNew Answer
print("Python is fun") Doesn't gives ouput in single quotes But this does print(" 'Python is fun' ")
Here are the different ways to manipulate strings. print("saga") print("'saga'") print('saga') print('"saga"') print("\"saga\"") print('\'saga\'')
When you define a string, for example... x = 'Hello' ... the quotes are just used to tell Python: Please make a string! The actual string is just: Hello And if you use print, this is all you get. When you are in an interpreter session, where every line of code is executed automatically, every value will be shown on the screen. You don't see the actual string (which is still just Hello) but a representation of that string. Just as a tuple will always look like this... (1, 2, 3) ... and a list like this... [1, 2, 3] ... a string always has the same representation, with single quotes, even if you have defined it with double or even triple quotes. You can test that with different ways of defining a string: a = 'Hello' b = "Hello" c = '''Hello''' d = """Hello""" for string in a, b, c, d: print(repr(string))
Amisha Agarwal can you show in codeplayground please? I can't believe what you say.
Because by default console output shows string into single quotes. >>>a = "Python is fun" >>>a 'Python is fun' >>>print(a) Python is fun >>>str(a) 'Python is fun'
$¢𝐎₹𝔭!𝐨𝓝 that's it! great answer!
Amisha Agarwal You should also know that you can show the single quotes of a string if you run the code in interpreter See the example below 👇👇👇 >>> a="Python is fun" >>> a 'Python is fun' >>>
Oma Falk Thanks