格式化输出format 几种方法

格式化输出的几种方法:

# s1 = s.format()            #格式化输出
# # #三种方 1. 直接赋值
s = "我叫{},我今年{},我喜欢{}".format("小白","18","跳舞")
print(s)
#
# # 方法 2. 索引赋值
s = "我叫{2},我今年{0},我喜欢{1}".format("18","跳舞","小白")
print(s)
#
# #方法 3. 键值对 键赋值
s = "我叫{name},我今年{age},我喜欢{bol}".format(age="18",bol="跳舞",name="小白")
print(s)
#
# #导入方式赋值 索引导入
name = input("请输入您的姓名:")
age = input("请输入您的年龄:")
bol = input("请输入您喜欢的运动:")
s = "我叫{0},我今年{1},我喜欢{2}".format(name,age,bol)
print(s)
#导入方法2 键值对 键导入
name = input("请输入您的姓名:")
age = input("请输入您的年龄:")
bol = input("请输入您喜欢的运动:")
s = "我叫{name},我今年{age},我喜欢{bol}".format(name=name,age=age,bol=bol)
print(s)

猜你喜欢

转载自www.cnblogs.com/yexingyi/p/12460167.html