types_of_people = 10 # 给变量赋值
x = f"There are {types_of_people} types of people." # 将字符串赋值给X了
binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}." # 第一处
print(x) # There are 10 types of people.
print(y) # Those who know binary and those who don't.
print(f"I said: {x}") # I said: There are 10 types of people. 第二处
print(f"I also said: '{y}'") # I slso said: those who know binary and those who don't. 第三处
hilarious = False
joke_evaluation = "Isn't that joke so funny? {}!"
print(joke_evaluation.format(hilarious)) # Isn't that joke so funny? False 注意错误:感叹号!第四处
# A.format{B} 将B赋值给A中的{}位置
w = "This is the left side of..."
e = "a string with a right side."
print(w+e) # This is the left side of... a string with a right side.注意错误...后面没有空格
"""
format()
主要格式:print('{ } { }'.format('字符串1', '字符串2'))
foramt会把参数按位置顺序来填充到字符串中(按照顺序自动分配),第一个参数是0,然后1 ……
也可以不输入数字,则会按照顺序自动分配,而且一个参数可以多次插入
一个参数可以多次插入
{{}}
仅代表
{},不占用字符串格式化位置顺序
"""
types_of_people = 10 # 给变量赋值
x = f"There are {types_of_people} types of people." # 将字符串赋值给X了
binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}." # 第一处
print(x) # There are 10 types of people.
print(y) # Those who know binary and those who don't.
print(f"I said: {x}") # I said: There are 10 types of people. 第二处
print(f"I also said: '{y}'") # I slso said: those who know binary and those who don't. 第三处
hilarious = False
joke_evaluation = "Isn't that joke so funny? {}!"
print(joke_evaluation.format(hilarious)) # Isn't that joke so funny? False 注意错误:感叹号!第四处
# A.format{B} 将B赋值给A中的{}位置
w = "This is the left side of..."
e = "a string with a right side."
print(w+e) # This is the left side of... a string with a right side.注意错误...后面没有空格
"""
format()
主要格式:print('{ } { }'.format('字符串1', '字符串2'))
foramt会把参数按位置顺序来填充到字符串中(按照顺序自动分配),第一个参数是0,然后1 ……
也可以不输入数字,则会按照顺序自动分配,而且一个参数可以多次插入
一个参数可以多次插入
{{}}
仅代表
{},不占用字符串格式化位置顺序
"""