Python print | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python print

In python print code, Output of print("same") and print('same') are same. Is there any difference with " and ' ? Please help me. Thank you.

28th Sep 2017, 4:16 PM
Ji Hoon Kim
Ji Hoon Kim - avatar
2 Answers
+ 6
I don't deal with Python much these days, but if it's anything like most languages, then it's good for formatting strings sometimes. For example, instead of doing "This is an \"example\" of ugly formatting." you could do 'This is an "example" of prettier formatting.' Again, I don't mess with Python much these days, so I can't tell you 100% that I'm right on that in regard to Python, but often that's the case. In some others, it's good practice to reserve it for single chars, but use your own discernment with it and what works best for you. I'm sure some Pythonites can correct me if I'm wrong.
28th Sep 2017, 4:31 PM
AgentSmith
+ 6
No difference and you can use this feature, like Netkos suggested, for enveloping one type of quotes to pass as a regular character without the need of escaping it, provided you use the other type as designation of the string. Just an add-on, you can use triple single or triple double quotes for marking docstrings, so a type of strings which look *exactly* as they are typed. Most often they are used as multiline comments, though.
28th Sep 2017, 5:26 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar