+ 1
Explain me the use of single quotation and double quotation in python
2 Respostas
+ 6
Quotations are used to denote strings.
You can use either " ", or ' ' which will do the same thing.
String = "test"
String = 'test'
However here's the trick.
Sometimes you may wish to print something like (don't do it).
If you were to print('don't do it'), you will get an error because the string will escape the code too early.
You will need print("don't do it") to successfully print your message.
Another example:
print('She said, "How are you"?')
You can also use an escape character for complicated scenarios.
print('She said, "Don\'t do it" ')
0
Please tag 'Python string' 👍