我也打算开始写博客啦!记录一下自己的学习过程~
01密文登陆
这个在vscode中不显示密文
在cmd中看不到密码
# -*- coding: utf-8 -*- import getpass name = input("please input your name:")
password = getpass.getpass('please put in your password:')
if name == "xb" and password == "":
print("welcome!")
else:
print("you have put in the wrong information!")
print(name, password)
02各种变量的空值
数值 |
digital = 0 |
字符串 |
str = "" 或 str = ” |
列表 |
list = [] |
字典 |
ditc = {} |
元组 |
tuple= () |
03占位符
(1)%
tpl = "i am %s" % "alex" tpl = "i am %s age %d" % ("alex", 18)
tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}
tpl = "percent %.2f" % 99.97623
tpl = "i am %(pp).2f" % {"pp": 123.425556, }
tpl = "i am %.2f %%" % {"pp": 123.425556, }
(2)Format
tpl = "i am {}, age {}, {}".format("seven", 18, 'alex') tpl = "i am {}, age {}, {}".format(*["seven", 18, 'alex']) tpl = "i am {0}, age {1}, really {0}".format("seven", 18) tpl = "i am {0}, age {1}, really {0}".format(*["seven", 18]) tpl = "i am {name}, age {age}, really {name}".format(name="seven", age=18) tpl = "i am {name}, age {age}, really {name}".format(**{"name": "seven", "age": 18}) tpl = "i am {0[0]}, age {0[1]}, really {0[2]}".format([1, 2, 3], [11, 22, 33]) tpl = "i am {:s}, age {:d}, money {:f}".format("seven", 18, 88888.1) tpl = "i am {:s}, age {:d}".format(*["seven", 18]) tpl = "i am {name:s}, age {age:d}".format(name="seven", age=18) tpl = "i am {name:s}, age {age:d}".format(**{"name": "seven", "age": 18}) tpl = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}".format(15, 15, 15, 15, 15, 15.87623, 2) tpl = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%}".format(15, 15, 15, 15, 15, 15.87623, 2) tpl = "numbers: {0:b},{0:o},{0:d},{0:x},{0:X}, {0:%}".format(15) tpl = "numbers: {num:b},{num:o},{num:d},{num:x},{num:X}, {num:%}".format(num=15)
04登陆交互程序
# -*- coding: utf-8 -*- print("----------welcome---------")
i = 0
LockedName = ""
name = ""
while i < 3:
name = input("please input your name:")
password = input('please put in your password:')
if name == LockedName:
print("You have been locked")
if name == "xb" and password == "":
print("-----------------")
print("welcome!")
print("name:%s,\npassword:%s" % (name, password))
exit()
else:
print("try again")
if i == 2:
LockedName = name
print("your account has been locked!!!")
i = i + 1