Python中格式化输出的三种方式

1. 格式化输出的三种方式

name = 'Nick'
height = 180
weight = 140

# "My name is 'Nick', my height is 180, my weight is 140"

# 第一种%s格式化
print("My name is %s, my height is %s, my weight is %s" %(name, height, weight))
# 第二种.format格式化
print("My name is {}, my height is {}, my weight is {}".format(name, height, weight))
# 第三种f格式化
print(f"My name is {name}, my height is {height}, my weight is {weight}")
posted @ 2019-07-31 15:22  17vv  阅读(251)  评论(0编辑  收藏  举报