1 #Python3 格式化输出 占位符%s %d %f 2 name = input("Name:") 3 age = int(input("Age:")) 4 #input默认接受的都是字符串类型,所以要输出%d整型,就要先把字符串强制转换成整型 5 job = input("Job:") 6 salary = input("Salary:") 7 8 info = """ 9 ---------info of %s--------- 10 Name:%s 11 Age:%d 12 Job:%s 13 Salary:%s 14 """ % (name, name, age, job, salary) 15 print(info) 16 17 #格式化输出 format 18 name = input(‘Name:‘) 19 age = int(input(‘Age:‘)) 20 job = input(‘Job:‘) 21 salary = input(‘Salary:‘) 22 23 info1 = """ 24 --------info of {Name}-------- 25 Name:{Name} 26 Age:{Age} 27 Job:{Job} 28 Salary:{Salary} 29 """.format(Name=name, Age=age, Job=job, Salary=salary) 30 print(info1) 31 32 #还可以这样写,但是一般不用,太low,不够清晰 33 info2 = """ 34 --------info of {0}-------- 35 Name:{0} 36 Age:{1} 37 Job:{2} 38 Salary:{3} 39 """.format(name, age, job, salary) 40 print(info2)
1 for i in range(5): 2 print(‘i is ‘, i) #可以用逗号‘,‘ 进行连接 3 4 """ 5 结果是: 6 i is 0 7 i is 1 8 i is 2 9 i is 3 10 i is 4 11 """
原文地址:https://www.cnblogs.com/skings/p/10260987.html
时间: 2024-10-09 09:33:48