欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

oldboy python 3.5 week 1

程序员文章站 2022-04-11 16:10:51
看着视频学了老男孩PYTHON并作笔记 首先来一个程序员的仪式 print("hello world") #!/usr/bin/env python # -*- coding:utf-8 -*- ......

看着视频学了老男孩python并作笔记

首先来一个程序员的仪式

print("hello world")

#!/usr/bin/env python

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

-------------------------------------------
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)

------------------------------------------

此时都是明文输入 如果需要密文输入时 可用如下代码
------------------------------------------
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!")