2019-03-14
阅读量:
531
python的PEP 8风格是什么?
对于Python,PEP 8已经成为大多数项目所遵循的风格指南; 它促进了一种非常易读且令人赏心悦目的编码风格。每个Python开发人员都应该在某个时候阅读它; 以下是为您提取的
最重要的要点:
1.使用4空格缩进而没有标签。
例子:
:
# Aligned with opening delimiter.
grow = function_name(variable_one, variable_two,
variable_three, variable_four)
# First line contains no argument. Second line onwards
# more indentation included to distinguish this from
# the rest.
def function_name(
variable_one, variable_two, variable_three,
variable_four):
print(variable_one)
4空间规则并不总是强制性的,可以推迟继续行。
2.使用docstrings:可以在Python中使用单行和多行文档字符串。但是,单行注释适合一行,两种情况都使用三重引号。这些用于定义特定程序或定义特定功能。
例:
def exam():
"""This is single line docstring"""
"""This is
a
multiline comment"""






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论