鱼C论坛

 找回密码
 立即注册
查看: 2523|回复: 0

[技术交流] 复习

[复制链接]
发表于 2020-9-23 09:56:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1、字符串与字节的转换:
  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、登陆验证
  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. if _username == username and _password == password:
  9.     print('Welcome user {name} login'.format(name=username))
  10. else:
  11.     print('Invalid username or password!')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-27 15:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表