python交互模式_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)
python单例模式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)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。