没有合适的资源?快使用搜索试试~ 我知道了~
Python精准必看—PEP8代码编写规范
需积分: 9 1 下载量 104 浏览量
2018-11-29
19:17:59
上传
评论
收藏 31KB DOCX 举报
温馨提示
新手入门python必看的编写标准,养成一个好习惯很重要 1.代码布局设计 1.1 缩进 A、 使用四个空格来进行缩进 B、 换行的时候可以使用反斜杠,最好的方法是使用圆括号,在使用反斜杠的时候,在反斜杠的后直接回车,不能有任何空格存在。 比较好的做法如下:
资源推荐
资源详情
资源评论
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![jpg](https://img-home.csdnimg.cn/images/20210720090814.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/10817609/bg1.jpg)
1.代码布局设计
1.1 缩进
A、使用四个空格来进行缩进
B、换行的时候可以使用反斜杠,最好的方法是使用圆括号,在使用反斜杠的时候,在反
斜杠的后直接回车,不能有任何空格存在。
比较好的做法如下:
# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
var_three, var_four)
包含更多的缩进表示是剩余部分:
# More indentation included to distinguish this from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
悬挂缩进应该添加一个级别:
# Hanging indents should add a
level.
foo = long_function_name(
var_one, var_two,
var_three, var_four)
比较差的做法如下:(代码同样是可以运行的)
# Arguments on !rst line forbidden when not using vertical
![](https://csdnimg.cn/release/download_crawler_static/10817609/bg2.jpg)
alignment.—未使用垂直对齐
foo = long_function_name(var_one, var_two,
var_three, var_four)
# Further indentation required as indentation is not distinguishable.
(未使用缩进来表示每一层级)
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
对于续行来说,四个空格的缩进是可选的。
可选的如下:
# Hanging indents *may* be indented to other than 4 spaces.悬挂缩
进的时候可以不是四个空格
foo = long_function_name(
var_one, var_two,
var_three, var_four)
当使用 if 语句的时候,如果条件恰好的缩进为四个空格空格,那么导致后面的语句的缩进
也是四个空格,那么这种情况下是可以接受的,如下所示:
没有额外的缩进:
# No extra indentation.
if (this_is_one_thing and
![](https://csdnimg.cn/release/download_crawler_static/10817609/bg3.jpg)
that_is_another_thing):
do_something()
添加一个注释来进行分割缩进,做到语法高亮显示:
# Add a comment, which will provide some distinction in
editors
# supporting syntax highlighting.
if (this_is_one_thing and
that_is_another_thing):
# Since both conditions are true, we can frobnicate.
do_something()
在续行中添加额外的缩进:
# Add some extra indentation on the conditional continuation
line.
if (this_is_one_thing
and that_is_another_thing):
do_something()
成对的小括号,中括号在多行的结构中可以写成多行,然后括号在第一个不为空白的位置
结束。如下:
my_list = [
1, 2, 3,
4, 5, 6,
]
result =
some_function_that_takes_arguments(
'a', 'b', 'c',
'd', 'e', 'f',
剩余18页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/e6624a913edc49069c2506f3fc43a074_wo704566930.jpg!1)
只求世间无巴格
- 粉丝: 1
- 资源: 28
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)