#进行交互,row_input在python3里面等同于input
1 username = input("username:") 2 job = input("your job:") 3 age = int(input("your age:")) #string转换成int
#字符串拼接↓
1 info = ‘‘‘ 2 ------now-------------- 3 Name:‘‘‘+ username +‘‘‘ 4 job:‘‘‘ + job + ‘‘‘ 5 ‘‘‘ 6 #---------------------- 7 info_2 = ‘‘‘ 8 ------now_2-------------- 9 Name:%s #字符串string 10 job:%s 11 age:%d #只能是int 12 ‘‘‘ % (username,job,age) 13 14 info_3 =‘‘‘ 15 ------now_3-------------- 16 Name:{name_1} 17 job:{job_2} 18 age:{age_3} 19 ‘‘‘.format(name_1=username,job_2=job,age_3=age) #{}里面的参数可以自己定义 20 21 print(info,‘\n‘) 22 print(info_2) 23 print(info_3) 24 #判断类型 25 print(type(age))
#输出结果
1 username:gdr 2 your job:it 3 your age:24 4 5 ------now-------------- 6 Name:gdr 7 job:it 8 9 10 11 ------now_2-------------- 12 Name:gdr #字符串string 13 job:it 14 age:24 #只能是int 15 16 17 ------now_3-------------- 18 Name:gdr 19 job:it 20 age:24 21 22 <class ‘int‘>
时间: 2024-10-08 13:44:48