input 用户交互函数
使用input函数需用户键盘输入变量,多种表达方式
注重在python中 “”与‘’ 是没区别的,所见即所得,未加“”示意引用变量,在shell“”会举行转义

name = input("your name:")
print(input("your name:"))
your name:dwl

常用占位符
%d 整数
%f 浮点数
%s 字符串
%x 十六进制整数
使用方式:

tpl = "i am %s" % "alex" ## i am alex
tpl = "i am %s age %d" % ("alex", 18)  ## i am alex age 18
tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}  # i am alex age 18 (注重其中占位符的写法,使用key value的方式)
tpl = "percent %.2f" % 99.97623 #percent 99.98'  .2f% 示意小数点后两位四舍五入
tpl = "i am %(pp).2f" % {"pp": 123.425556, } # i am 123.43

FoRMat方式:

tpl = "i am {}, age {}, {}".format("seven", 18, 'alex') 
 ##i am seven, age 18, alex 注重.format的誊写位置在“”后面,文字按顺序补全
tpl = "i am {}, age {}, {}".format(*["seven", 18, 'alex'])

tpl = "i am {0}, age {1}, really {0}".format("seven", 18)
 ##文字顺序 0,1,2最先 
tpl = "i am {0}, age {1}, really {0}".format(*["seven", 18])

综合演习:

#!/usr/bin/env python
# -*- coding:utf-8 -*-
name=input("name:")   
age=int(input("age:"))   ##使用int 字符类型转换函数 为使跟%d 类型相匹配
job=input("job:")
salary=input("sarlary:")
info='''---------info of %s ---------
name:%s
age:%d    
job:%s
salary:%s
'''%(name,name,age,job,salary)
print(info)

info2='''---------info2 of {_name} ---------
name:{_name}
age:{_age}
job:{_job}
salary:{_salary}'''.format(_name=name,_age=age,_job=job,_salary=salary)
print(info2)