python_4_interaction
#1(方法1)尽量不用这种拼接法,效率低下,占用内存多 name=input("name:") age=input('age:') job=input('job:') salary=input("salary:") info=''' ------- info of ''' + name +'''------- Name:''' + name +''' Age:''' + age + ''' Job:''' + job + ''' Salary:''' + salary + ''' ''' print(info) #2(方法2) name=input("name:") age=int(input('age:'))#integer print(type(age)) #若又转回字符串 用str(age),例print(type(age),type(str(age))) job=input('job:') salary=input("salary:") info=''' ------- info of %s------- Name:%s Age:%d Job:%s Salary:%s '''%(name,name,age,job,salary) print(info) #注: %s:string %d:整数 %f:浮点(简单理解为小数) #3(方法3) name=input("name:") age=input('age:') job=input('job:') salary=input("salary") info=''' ------- info of {xinming}------- Name:{xinming} Age:{nianlin} Job:{gongzuo} Salary:{gongzi} '''.format(xinming=name,nianlin=age,gongzuo=job,gongzi=salary) print(info) #4(方法4) name=input("name:") age=input('age:') job=input('job:') salary=input("salary") info=''' ------- info of {0}------- Name:{0} Age:{1} Job:{2} Salary:{3} '''.format(name,age,job,salary) print(info)