- 用户交互程序
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:%sage%dsalary:%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))