python交互的几种方式

# 第一种交互方式

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(name,age,job,salary)
# 第二种交互方式 %s 字符串  %d  整数   %f 浮点数  %.2f 浮点数保留两位
name = input("name:")
age = input("age:")
age = int(input("age:")) # 强制转换成int
print(type(age)) # 打印一个变量的数据类型
#print(type(str(age)))# 整型转换成字符串
job = input("job:")
salary = input("salary:")
info = '''
---------- info of %s -----------
Name:%s
Age:%s
Job:%s
Salary:%s
''' %(name,name,age,job,salary)
print(info)
第三种交互方式
name = input("name:")
age = input("age:")
job = input("job:")
salary = input("salary:")
info = '''
---------- info of {_name} -----------
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
''' .format(_name=name,
_age=age,
_job=job,
_salary= salary)
print(info)
# 第四种交互方式
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)
上一篇:分离式部署LNMP


下一篇:python学习笔记(2):科学计算及数据可视化入门