注释
- 给一些晦涩难懂的代码进行标注或解释
- PEP8,不能超过规定的线
1. 单行注释: # xxx
2. 多行注释:
"""
xxx
"""
3. ctrl+/ 直接把圈起来的部分改成注释
条件判断(流程控制语句)
- =是赋值;
- ==是等于;
- !=是不等于
- :意味着语句结束
- 缩进:4个空格=tab
- tab不能和space混合使用,不然错误很难找
- 1个IF,if+else,if+elif+elif, if+elif+else, if嵌套, if+if+if+if
sex=input("请输入你的性别:") if sex == "girl": print("come on,baby!") else: print("go and find Xiaoming Huang, he is the same guy with you")sex=input("请输入你的性别:") if sex == "man": print("bye") elif sex == "girl": print("come on,baby!") else: print("go and find Xiaoming Huang, he is the same guy with you")sex=input("请输入你的性别:") man if sex == "girl": print("come on,baby!")- if语句不是必须要跟else,如3.就可以不输出。
practice
num=input("请输入你的年龄:") number=int(num) if number > 18 and number < 25: print("come on,baby!") else: print("That's not good") name=input("请输入你的名字:") password=input("请输入你的密码:") if name != "alex" or password != "oldboy": print("There is some wrong with your name or password!") else: print("land successfully") sex = input("请输入你的性别:") if sex == "man": print("go out and fuck yourself") else: age = int(input("请输入你的年龄:")) if age <= 25: print("hello") else: print("sorry,i`m so tired.") print("that`s a good night")- != 为 py3 中的不等号

若存在else,则必定会有一个输出,即“多选一”
if 嵌套
如果 条件:
缩进 如果 条件:
缩进 结果

if if if
常量
- 常量:变量名大写的就是常量。(非python中的定义,python中不存在常量)eg:ID
- 可以修改,但尽量别改
- 用于配置文件中
本文深入讲解Python编程中的注释规范,包括单行与多行注释的使用,以及条件判断语句的多种形式。通过实例演示了if语句的不同用法,如单一条件判断、多条件判断、嵌套if语句等,并介绍了常量的概念及其在配置文件中的应用。
123

被折叠的 条评论
为什么被折叠?



