Single and double quotes in Python
- There is no difference between single or double quotes in Python, and they can all represent a string.
- But these two general expressions can not only simplify the development of programmers and avoid errors, but also reduce the use of escape characters, making the program look more concise
- 1. A string containing single quotes
- A string my_str, the value is: I'm a student,
- It can be defined as follows by the escape character \
my_str = 'I\‘m a student’
- You can also use double quotes to define directly without escape characters
my_str = “I’m a student”
-
2. A string containing double quotes
-
I want to define a string my_str, the value is: Jason said "I like you"
-
Defined by the escape character \
-
my_str = “Jason said “I like you””
-
You can also use single quotes to directly define without escape characters
-
my_str = ‘Jason said “I like you”’