大家好,又见面了,我是你们的朋友全栈君。
实例
raw_input 2.x = input 3.x
age:数字类型
1 # author = "zhuyouen" 2 3 name = input("username:") 4 age = int(input("age:")) 5 #print(type(age),type(str(age))) 6 job = input("job:") 7 salary = input("salary:") 8 9 #raw_input 2.x = input 3.x 10 #input 2.x = 11 12 13 info2 = ''' 14 ----- info of {0} ------- 15 Name:{0} 16 Age:{1} 17 Job:{2} 18 Salary:{3} 19 ''' .format(name,age,job,salary) 20 print(info2)
username:fsdf age:123 job:2332 salary:123123 ----- info of fsdf ------- Name:fsdf Age:123 Job:2332 Salary:123123
age:字符串类型
1 # author = "zhuyouen" 2 3 name = input("username:") 4 age = input("age:") 5 #print(type(age),type(str(age))) 6 job = input("job:") 7 salary = input("salary:") 8 9 #raw_input 2.x = input 3.x 10 #input 2.x = 11 12 13 info2 = ''' 14 ----- info of {0} ------- 15 Name:{0} 16 Age:{1} 17 Job:{2} 18 Salary:{3} 19 ''' .format(name,age,job,salary) 20 print(info2)
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0322/interaction.py username:asdhu age:sdva job:afvasfv salary:afsdvav ----- info of asdhu ------- Name:asdhu Age:sdva Job:afvasfv Salary:afsdvav Process finished with exit code 0
age:输入数字类型转换字符串类型
1 # author = "zhuyouen" 2 3 name = input("username:") 4 age = int(input("age:")) 5 print(type(age),type(str(age))) 6 job = input("job:") 7 salary = input("salary:") 8 9 #raw_input 2.x = input 3.x 10 #input 2.x = 11 12 13 info2 = ''' 14 ----- info of {0} ------- 15 Name:{0} 16 Age:{1} 17 Job:{2} 18 Salary:{3} 19 ''' .format(name,age,job,salary) 20 print(info2)
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0322/interaction.py username:kzjv age:123 <class 'int'> <class 'str'> job:it salary:10000 ----- info of kzjv ------- Name:kzjv Age:123 Job:it Salary:10000 Process finished with exit code 0
方式2
%d 数字
%f 浮点
1 # author = "zhuyouen" 2 3 name = input("username:") 4 age = int(input("age:")) 5 #print(type(age),type(str(age))) 6 job = input("job:") 7 salary = input("salary:") 8 9 #raw_input 2.x = input 3.x 10 #input 2.x = 11 12 13 info2 = ''' 14 ----- info of %s ------- 15 Name:%s 16 Age:%d 17 Job:%s 18 Salary:%s 19 ''' % (name,name,age,job,salary) 20 print(info2)
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0322/interaction.py username:xcvx age:123 job:sdf salary:dsf ----- info of xcvx ------- Name:xcvx Age:123 Job:sdf Salary:dsf
方式3
1 # author = "zhuyouen" 2 3 name = input("username:") 4 age = int(input("age:")) 5 #print(type(age),type(str(age))) 6 job = input("job:") 7 salary = input("salary:") 8 9 #raw_input 2.x = input 3.x 10 #input 2.x = 11 12 13 info2 = ''' 14 ----- info of {_name} ------- 15 Name:{_name} 16 Age:{_age} 17 Job:{_job} 18 Salary:{_salary} 19 ''' .format (_name=name, 20 _age=age, 21 _job=job, 22 _salary=salary) 23 print(info2)
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0322/interaction.py username:zhuyouen age:123 job:asd salary:dsf ----- info of zhuyouen ------- Name:zhuyouen Age:123 Job:asd Salary:dsf
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/155991.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...