最后一种避免字符串被转义的方法是使用三重引号(‘’'或"“”),这种方式可以让字符串中包含任意字符而不会被转义。 # 使用三重引号triple_quote_str='''This is a string with special characters: \n\t'''print(triple_quote_str)# 输出结果为:This is a string with special characters: \n\t 1. 2...
For example, if you need to represent an apostrophe in a string, then you can enclose your text in double quotes. Alternatively, you can use multiline strings to mix both types of delimiters in the text.You may use triple quotes (''' or """) to declare a multiline string literal ...
single_quote ='a'# This is an example of a character in other programming languages. It is a string in Python # Another single quote string another_single_quote ='Programming teaches you patience.' # A double quote string double_quote ="aa" # Another double-quote string another_double_quo...
single_quote = 'a' # This is an example of a character in other programming languages. It is a string in Python # Another single quote string another_single_quote = 'Programming teaches you patience.' # A double quote string double_quote = "aa" # Another double-quote string another_doub...
The triple quote is most useful for docstrings and raw string literals definition. The triple quote may wrap multiple lines like below. 三重引号对于文档字符串和原始字符串文字定义最有用。 三重引号可能会包裹多行,如下所示。 sss='''This
It is a string in Python # Another single quote string another_single_quote = 'Programming teaches you patience.' # A double quote string double_quote = "aa" # Another double-quote string another_double_quote = "It is impossible until it is done!" # A triple quote string triple_quote ...
Unfortunately these methods do not give us a newline between the two lines of the sonnet(十四行诗). Instead, we can use atriple-quotedstring as follows: >>>couplet="""Shall I compare thee to a Summer's day? ... Thou are more lovely and more temperate:""" ...
>>> '''A triple-quoted string ... spanning across multiple ... lines using single quotes''' 'A triple-quoted string\nspanning across multiple\nlines using single quotes' >>> """A triple-quoted string ... spanning across multiple ... lines using double quotes""" 'A triple-quoted str...
# 单引号(Single quote) a = 'Yeah but no but yeah but...' # 双引号(Double quote) b = "computer says no" # 三引号(Triple quotes) c = ''' Look into my eyes, look into my eyes, the eyes, the eyes, the eyes, not around the eyes, don't look around the eyes, look into my...
Python strings can be created with single quotes, double quotes, or triple quotes. When we use triple quotes, strings can span several lines without using the escape character. string_literals.py #!/usr/bin/python # string_literals.py