用户交互程序,格式化输出
- 用户交互程序
name = input("name:") age = int(input("age:"))#intege整数 salary = float(input("salary:"))#浮点型
- 格式化输出:
- %s %d %f
name = input("name:") age = int(input("age:"))#intege整数 salary = float(input("salary:"))#浮点型 msg = ''' ---------info of %s-------------- name:%s age%d salary:%f '''%(name,name,age,salary)#里面的%s等对应个数需要与这里一致,按照顺序排列 print(msg)
- {}
name = input("name:") age = int(input("age:"))#intege整数 salary = float(input("salary:"))#浮点型 msg = ''' ---------info of {_name}-------------- name:{_name} age:{_age} salary:{_salary} '''.format(_name = name, _age = age, __salary = salary) print(msg)
- 类型转换
type()显示对应类型,int:整型 str:字符 float:浮点型
name = input("name:") age = int(input("age:"))#intege整数 salary = float(input("salary:"))#浮点型 print(type(name)) print(type(age)) print(type(salary)) str(age)#转换为string字符类型 print(type(age))