1 通过input函数字符串输入
name=input("name:")
print(name)
2 输入密码,需要导入getpass,在一些IDE中仍会显示明文密码
import getpass
name=input("name:")
password=getpass.getpass("password:")
print(name,password)
3 字符串中变量赋值
方式1:
name=input("name:")
age=input("age;")
salary=input("salary:")
info='''
------info {_name}-------
name:{_name}
age:{_age}
salary:{_salary}
----------------------
''' .format(_name=name,
_age=age,
_salary=salary)
print(info)
方式2:
name=input("name:")
age=input("age;")
salary=input("salary:")
info='''
------info {0}-------
name:{1}
age:{2}
salary:{3}
----------------------
''' .format(name,name,age,salary)
print(info)
方式3:
info='''
------info %s-------
name:%s
age:%s
salary:%s
----------------------
''' % (name,name,age,salary)
4 声明使用utf-8b编码
# -*- coding: utf-8 -*-