0

quote confusion

In the code "Python is fun" u have used double quotes and the output that we get is in single quotes ,why?

28th May 2020, 3:20 PM
Amisha Agarwal
Amisha Agarwal - avatar
8 Antworten
+ 3
print("Python is fun") Doesn't gives ouput in single quotes But this does print(" 'Python is fun' ")
28th May 2020, 3:22 PM
Abhay
Abhay - avatar
+ 1
Here are the different ways to manipulate strings. print("saga") print("'saga'") print('saga') print('"saga"') print("\"saga\"") print('\'saga\'')
28th May 2020, 3:30 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
+ 1
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))
28th May 2020, 3:30 PM
HonFu
HonFu - avatar
+ 1
Amisha Agarwal can you show in codeplayground please? I can't believe what you say.
29th May 2020, 5:57 AM
Oma Falk
Oma Falk - avatar
+ 1
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'
29th May 2020, 6:22 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
+ 1
$¢𝐎₹𝔭!𝐨𝓝 that's it! great answer!
29th May 2020, 6:23 AM
Oma Falk
Oma Falk - avatar
0
Oma Falk Thanks
29th May 2020, 7:03 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar