oldboy python 3.5 we

2020-01-17 13:10:52 浏览数 (1)

#!/usr/bin/env python

# -*- coding:utf-8 -*-

代码语言:javascript复制
-------------------------------------------
代码语言:javascript复制
name = input("name:")
age = int(input("age:") ) #integer
job = input("job:")
salary  = input("salary:")

info = '''
-------- info of  %s  -----
Name:%s
Age:%d #使用%d就只能输入数字 否则报错
Job:%s
Salary:%s
''' % (name,name,age,job,salary)

#print(type(age)   , type(  str(age) ))------改变变量

info2 = '''
-------- info of {_name}  -----
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
'''.format(_name=name,
           _age=age,
           _job=job,
           _salary=salary)

info3 =  '''
-------- info of {0} -----
Name:{0}
Age:{1}
Job:{2}
Salary:{3}
'''.format(name,age,job,salary)
print(info, info2, info3)
代码语言:javascript复制
------------------------------------------

此时都是明文输入 如果需要密文输入时 可用如下代码
------------------------------------------
代码语言:javascript复制
import getpass

_username = 'shing'
_password = 'abc123'
username = input("username:")
#password = getpass.getpass("password:")
password = input("password:")
if _username == username and _password == password:
    print("Welcome user {name} login...".format(name=username))
else:
    print("Invalid username or password!")

0 人点赞