+ 1

Which is better, single or double quotes in Python?

I’ve noticed Sololearn uses both single and double quotes for strings and Python code in general. Which is more conventional? Or more widely used? I find using both in this app confusing. Thanks!

8th Feb 2021, 4:00 AM
DigiDragon
DigiDragon - avatar
9 odpowiedzi
+ 5
In my early days of learning Python, I always use single quotation marks ' ' But since I started to learn C++ in which the single quotation mark ' ' is used for char data type and not string, I started to use double quotation marks instead. If you know you will learn other programming language, then use double quotation mark so you won't get confused and to have no need to adjust.
8th Feb 2021, 6:59 AM
noteve
noteve - avatar
+ 3
It's better to know how both can be used. Then you can pick your favourite one and use it.
8th Feb 2021, 4:08 AM
CHANDAN ROY
CHANDAN ROY - avatar
+ 2
in C we use ' ' single quotes to store char and " " quotes to store strings in python you can use both if you want to use single quote in your string then you have to store that string inside double quotes and vice versa.. Ex. print("I'll be their") print(' he said, "I will come" ') look the quotes carefully!
8th Feb 2021, 4:32 AM
Ratnapal Shende
Ratnapal Shende - avatar
+ 1
Good to know. Thanks!
8th Feb 2021, 4:12 AM
DigiDragon
DigiDragon - avatar
+ 1
Use single quotes sir. It is better because I said so.
8th Feb 2021, 4:35 PM
Big Joe
Big Joe - avatar
+ 1
thanks for all the great advice!
10th Feb 2021, 3:26 AM
DigiDragon
DigiDragon - avatar
0
I learned python in a different couse which traditionally used double quotes, so of course I naturally feel that’s better 😺. Also, if you’re going to use an apostrophe in the string, double quotes are definitely better.
9th Feb 2021, 2:55 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
it’s like commas in grammar. Some teachers love commas and use them as often as they can, other teachers hate them. It depends on who taught you, really, and whats more readable in the code.
9th Feb 2021, 2:57 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
Always aim for clarity. 😊
9th Feb 2021, 2:58 PM
Wilbur Jaywright
Wilbur Jaywright - avatar