1、字符串与字节的转换:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # byte to string 2 msg = '我爱祖国' 3 print(msg) 4 print('--', msg.encode()) # 进行字节编码 5 # 或者print(msg.encode(encoding='utf-8')) 6 # python3.8系统默认编码是utf-8 7 print('--', msg.encode().decode()) # 解码回到字符串
2、for 循环
1 for i in range(10): 2 if i < 3: 3 print('loop',i) 4 else: 5 continue 6 #continue是用来跳出本次循环后继续下次循环;而break是用来结束整个循环 7 #那么调试(debug),会发现i=3之后都没有打印hehe... 8 print('hehe...') 9 for i in range(0,10,2): 10 print('输出0-9之间的偶数',i)
3、登陆验证
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 import getpass 2 _username = 'Flagon'; _password = 'abc' 3 username = input("请输入用户名:") 4 password = input("请输入密码:") 5 # password = getpass.getpass("请输入密码:") # 这是不显示输入的密码 6 print('username:', username) 7 print('password:', password) 8 9 if _username == username and _password == password: 10 print('Welcome user {name} login'.format(name=username)) 11 else: 12 print('Invalid username or password!')