注释
# 单行注释
''' 多行注释 ''' 或者 """ 多行注释 """
# Author: Itxpl mag = ''' usersname = input("usersname:") password = input("password:") print(username,password)''' print(mag) name = input("name:") age = int(input("age:")) #integer print(type(age)) job = input("job:") salary = input("salary:") info = ''' --------------- info of %s ------------------- Name:%s Age:%s Job:%s salary:%s ''' %(name,name,age,job,salary) #常用的是下面这一种 info2 = ''' ------------------info of {_name} -------------- Name:{_name} Age:{_age} Job:{_job} Salary:{_salary} '''.format(_name=name, _age=age, _job=job, _salary=salaty) info = ''' --------------------info of {0} ---------------- Name:{0} Age:{1} Job:{2} Salary:{3} '''.format(name,age,job,salary) print(info2)
用户输入
import getpass #调用python自带的库 username = input("username:") password = getpass.getpass("password:") print(username,password) #输入的密码是暗文,在python中不能执行,在其他解释器中可以 _username = "itxpl" _password = "asd123" username = input("username:") password = input("password:") if _username == username and _password == password: #加冒号 print("Welcome user {name} login...".format(name = username)) #自动缩进,强制,省掉了结束符,结构清晰 else: #和if是同级,所以不缩进 print("Invaid username or password!") # 是子语句
以上有个错误,
#输入密码是暗文,在pycharm中不能运行,不是python