quote confusion | Sololearn: Learn to code for FREE!

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?

5/28/2020 3:20:11 PM

Amisha Agarwal

8 Answers

New Answer

+3

print("Python is fun") Doesn't gives ouput in single quotes But this does print(" 'Python is fun' ")

+1

Here are the different ways to manipulate strings. print("saga") print("'saga'") print('saga') print('"saga"') print("\"saga\"") print('\'saga\'')

+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))

+1

Amisha Agarwal can you show in codeplayground please? I can't believe what you say.

+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'

+1

$¢𝐎₹𝔭!𝐨𝓝 that's it! great answer!

0

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' >>>

0

Oma Falk Thanks