用户交互程序,格式化输出

  • 用户交互程序
name = input("name:")
age = int(input("age:"))#intege整数
salary = float(input("salary:"))#浮点型
  • 格式化输出:
  1. %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)

 

  1. {}
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))

 

posted @ 2017-12-08 20:46  雨之愿风  阅读(108)  评论(0编辑  收藏  举报