|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1、字符串与字节的转换:
- # byte to string
- msg = '我爱祖国'
- print(msg)
- print('--', msg.encode()) # 进行字节编码
- # 或者print(msg.encode(encoding='utf-8'))
- # python3.8系统默认编码是utf-8
- print('--', msg.encode().decode()) # 解码回到字符串
复制代码
2、for 循环
- for i in range(10):
- if i < 3:
- print('loop',i)
- else:
- continue
- #continue是用来跳出本次循环后继续下次循环;而break是用来结束整个循环
- #那么调试(debug),会发现i=3之后都没有打印hehe...
- print('hehe...')
- for i in range(0,10,2):
- print('输出0-9之间的偶数',i)
复制代码
3、登陆验证
- import getpass
- _username = 'Flagon'; _password = 'abc'
- username = input("请输入用户名:")
- password = input("请输入密码:")
- # password = getpass.getpass("请输入密码:") # 这是不显示输入的密码
- print('username:', username)
- print('password:', password)
- if _username == username and _password == password:
- print('Welcome user {name} login'.format(name=username))
- else:
- print('Invalid username or password!')
复制代码 |
|