一、第一种,利用%(称之为:占位符)格式化输出:
?
s = """ ------------- info ------------- name:%s age:%s job:%s -------------- end ------------- """ name = input("name") age = int(input("age")) job = input("job") print(s%(name,age,job))
?
?二、第二种,f-String格式化(第二种格式化输出):
print(f"你是谁{任意的变量,和参数}") print(f"{alxe * 2}")#可以任意的运算 name = 'wupeiqi' age = 3 print(f"hello,{name},you are {age}") #输出: hello,wupeiqi,you are 30
?
三、第三种,利用format格式化输出format格式化(第三种格式化输出)?:
name = '阿瓦达所' age = 30 print("hello,{},you are {}".format(name,age)) #输出: hello,阿瓦达所,you are 30 ? name = 'alxsasd' age = 30 print("hello,{1},you are {0}".format(age,name))#索引是根据format后的数据进行的哦 #输出: hello,alxsasd,you are 30 ? name = '沛' age =78 print("hello,{name},you are {age}".format(age=age, name=name)) #输出: hello,沛,you are78
?
以上就是Python的三种格式化输出方式了?
|