+ 3

Single quotes vs. double quotes in Python

Hello. I am just wondering if it is okay if I use double quotes instead of single quotes while coding in Python? It seems to work with both but what is most desirable? Also if most people use single quotes then would it be okay for me to write double quotes in the same code if I am working on a shared project or would people mind? Example: print('hello world') vs. print("hello world")

28th Jan 2018, 11:03 AM
Anita Olsen
Anita Olsen - avatar
2 Antworten
+ 11
No actual difference. You often use one type as opening/closing, to fit the other one inside in order not to have to escape them. For example: s = 'She said: "Alright" and carried on' t = "That's fine, too." The problem starts when you want to make a string, like: She said: "Alright. That's fine, too." Then you have to escape one set either way.
27th Jan 2018, 9:48 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 6
Though both are permitted,it is more wise to use " " , because it supports to use apostrophe ( ' ) with a word.For example see the reply of @Kuba Siekierzyn'ski.
28th Jan 2018, 5:47 AM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar