51dev.com IT技术开发者社区

51dev.com 技术开发者社区

oldboy python 3.5 week 1

Pythonphp学习阅读(12)2019-10-10 收藏0次评论

看着视频学了老男孩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!")



以上就是oldboy python 3.5 week 1的全部内容,请多关注【51DEV】IT技术开发者社区。