F-strings can span multiple lines, making it easy to format longer messages or blocks of text. You can use triple quotes to create a multiline f-string and embed variables or expressions on any line. main.py #!/usr/bin/python name = 'John Doe' occupation = 'gardener' age = 34 msg ...
You can also use triple single (''') and triple double quotes ("""). All these string delimiters work for f-strings as well. This feature allows you to insert quotation marks in f-strings. It also lets you introduce string literals in the embedded expressions and even create nested f-...
下面是几种创建字符串的方式: # 单引号字符串single_quote_str='Hello, World!'print(single_quote_str)# 双引号字符串double_quote_str="Hello, Python!"print(double_quote_str)# 三引号字符串triple_quote_str="""This is a multi-line string. It can span multiple lines."""print(triple_quote_str...
# 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 ='''aaa''' # Also a triple quote string another_triple_quote ="""Welcome to the Python programming language. Ready...
triple_quote = '''aaa''' # Also a triple quote string another_triple_quote = """Welcome to the Python programming language. Ready, 1, 2, 3, Go!""" # Using the str() function string_function = str(123.45) # str() converts float data type to string data type ...
} >>> f"""Storing employee's data: { ... employee['name'].upper() # Always uppercase name before storing ... }""" File "<stdin>", line 3 }""" ^ SyntaxError: f-string expression part cannot include '#' In this example, you use triple quotes to build a string that spans ...
# 单引号(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, loo...
'# 双引号字符串double_quote_str="Hello, Python!"# 三重引号字符串triple_quote_str='''This is a multi-line string'''print(single_quote_str)print(double_quote_str)print(triple_quote_str) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
# 单引号(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