+ 2

' " or nothing in Python

How do you know if you're supposed to use ' " or nothing to surround text in Python?

24th Jun 2018, 1:01 PM
Alisse Canre
Alisse Canre - avatar
3 Antworten
+ 2
You need ' or " to make a string. What you use is a matter of style or convention both will work, just use them consistenly. ("this' is no good) I think mostly " are used for strings that represent sentences in human language like "hello world" and ' are used for more abstract strings like single charaters etc.
24th Jun 2018, 2:50 PM
deep_unlearning
deep_unlearning - avatar
+ 2
Text (strings) are always inside " or '. But make sure to use the same one as the start and end! "String"
24th Jun 2018, 2:50 PM
Paul Grasser
Paul Grasser - avatar
+ 1
You can use single or double inverted comma's to create string .but if you want to do tricks with your String then you can try both. e.g= x=('"Hi"') print(x) output="Hi" because "" is also a string here.
24th Jun 2018, 4:24 PM
Maninder $ingh
Maninder $ingh - avatar