The difference between single quotes, double quotes, and triple quotes in python
1 Common usage of single quotes and double quotes It is the same as the use of double quotes to represent string literals in C language.
eg:
(1) str1 = 'aaa' (等价于str = "aaa") (2) str2 = 'aaa,\ bbb' (等价于str2 = "aaa,\ bbb")
When printing str1 and str2, they are
aaa aaa,bbb
2 respectively. The difference between quotation marks and double quotation marks is mainly reflected in the fact that when the string enclosed in single quotation marks contains ", there is no need to use the escape character (\), and vice versa
(1) str1 = 'aaa"bbb' (2) str2 = "aaa'bbb"
Print str1, str2 respectively Yes
aaa"bbb aaa'bbb
3 There are two forms of triple quotation marks ("""String content""", or '''String content''')
<1>These two There is almost no difference in the usage of the form, but strictly speaking, there is the same difference as above
str1 = '''aaa"""bbb'''(等价于"""aaa\"""bbb""") str2 = """aaa'''bbb"""(等价于'''aaa\'''bbb''')
<2>The core usage of triple quotation marks is mainly reflected in cross-line strings, which will contain two delimiters All characters between symbols, including visible and invisible, such as carriage return and line feed characters
str1 = '''aaa bbb'''
Print str1
aaa bbb
Based on this feature of triple quotes, when formatting is required When entering multi-line characters, you can reduce the input of escape characters.
<3>Also, there are no multi-line comment symbols in python, so triple quotes are generally used instead
Related recommendations:《 Python Tutorial》
The above is the detailed content of The difference between python single quotes, double quotes, and triple quotes. For more information, please follow other related articles on the PHP Chinese website!