习题6 字符串和文本

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 ……
也可以不输入数字,则会按照顺序自动分配,而且一个参数可以多次插入
一个参数可以多次插入
{{}}
仅代表
{},不占用字符串格式化位置顺序
"""

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值