一、代码缩进和冒号
注意条件语句必须严格控制缩进,保证父句和子句的关系
num = 10
if num>5:
print('yes')
else:
print('no')
二、空行分隔代码段
例如if语句判断、while循环、for循环、def函数、class类等代码段前后最好留一行(人工分好段落)
# if语句
if num>5:
print('yes')
else:
print('no')
# for循环
for i in (1,2,4):
print(i)
# while循环
while i>3:
print('yes')
i+=1
else:
print('end')
# 函数定义
def show():
print(132)
# 类定义
class Person:
def show(self):
print(123)
三、包、模块的命名规范
1. 包——要求统一用小写(相当于文件夹)
2.模块——要求统一用小写(相当于文件夹里的文件)
四、类和对象的命名规范
1. 类——严格的驼峰式写法eg.IndexUserPerson
2. 对象——要求统一用小写
五、函数的命名规范
驼峰式写法 eg.indexUserPerson(不强行)
六、代码注释
1.单行注释——#
2.多行注释——(快捷键为Ctrl+/)
'''
三对单引号,python多行注释符
'''