python 格式化输出

1、使用%占位符

使用方式一:

name =input("请输入您的名字")
age = input("请输入您的年龄")
gender = input("请输入您的性别")
print("您的名字是%s,性别是%s,年龄是%s"%(name,gender,age))

使用方式二:

name =input("请输入您的名字")
age = input("请输入您的年龄")
gender = input("请输入您的性别")
print("您的名字是%(1)s,性别是%(2)s,年龄是%(3)s"%{'1':name,'2':gender,'3':age})

2、使用format

name =input("请输入您的名字")
age = input("请输入您的年龄")
gender = input("请输入您的性别")
print("您的名字是{0},您的年龄是{1},您的性别是{2}".format(name,age,gender))

 

posted on 2018-08-03 17:45  哟,写bug呢??  阅读(283)  评论(0编辑  收藏  举报

导航