str string
How to represent a string?
Single quotes, double quotes, triple quotes
Single and double quotes must appear
in pairs . If there are single quotes in the string, the string is enclosed in double quotes
. If there are double quotes in the string, the string is enclosed in single quotes.
>>> 'let's go'
SyntaxError: invalid syntax
>>> "let's go" //推荐使用这个方式表示
"let's go"
>>> 'let"s go'
'let"s go'
>>> 'let\'s go'//\是转义字符
"let's go"
Three quotation marks (three single quotation marks, three double quotation marks) can solve the carriage return problem and realize the multi-line definition of the string
>>> '''
hello world
hello
world
'''
'\nhello world\nhello\nworld\n'
>>> """
hello world
hello
world
"""
'\nhello world\nhello\nworld\n'
>>> """hello
world"""
'hello\nworld'
>>> """hello world\nhello world\nhello world"""
'hello world\nhello world\nhello world'
//注意引号内是字符串内容不能输出回车
Use the print function to print the carriage return
>>> print("""hello world\nhello world\nhello world""")
hello world
hello world
hello world
>>> print("hello world\nhello world\nhello world")
hello world
hello world
hello world
Single quotes for line breaks
>>> 'hello\
world'
'helloworld'