Python注释规范、代码规范和命名规范是什么
Admin 2022-08-10 群英技术资讯 1413 次浏览
今天就跟大家聊聊有关“Python注释规范、代码规范和命名规范是什么”的内容,可能很多人都不太了解,为了让大家认识和更进一步的了解,小编给大家总结了以下内容,希望这篇“Python注释规范、代码规范和命名规范是什么”文章能对大家有帮助。

reStructuredText(PyCharm默认)
def func(path, field_storage, temporary):
'''基本描述
详细描述
:param path: The path of the file to wrap
:type path: str
:param field_storage: The :class:`FileStorage` instance to wrap
:type field_storage: FileStorage
:param temporary: Whether or not to delete the file when the File instance is destructed
:type temporary: bool
:returns: A buffered writable file descriptor
:rtype: BufferedFileStorage
'''
pass
NumPy
def func(path, field_storage, temporary):
'''基本描述
详细描述
Parameters
----------
path : str
The path of the file to wrap
field_storage : FileStorage
The :class:`FileStorage` instance to wrap
temporary : bool
Whether or not to delete the file when the File instance is destructed
Returns
-------
BufferedFileStorage
A buffered writable file descriptor
'''
pass
Google(官方推荐)
def func(path, field_storage, temporary):
'''基本描述
详细描述
Args:
path (str): The path of the file to wrap
field_storage (FileStorage): The :class:`FileStorage` instance to wrap
temporary (bool): Whether or not to delete the file when the File instance is destructed
Returns:
BufferedFileStorage: A buffered writable file descriptor
'''
pass
| 风格 | 特点 | 适用 |
|---|---|---|
| reStructuredText | 用冒号分隔 | PyCharm默认 |
| NumPy | 用下划线分隔 | 倾向垂直,长而深的文档 |
| 用缩进分隔 | 倾向水平,短而简单的文档 |
Sphinx对NumPy和Google风格的对比,英文不好可以参考中文版
在PyCharm中Ctrl+Q可快速查看注释

注意条件语句必须严格控制缩进,保证父句和子句的关系
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多行注释符'''
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
Scipy是Python算法库和数学工具包,包括最优化、线性代数、积分、插值、特殊函数、傅里叶变换等模块。scipy.optimize模块中提供了多个用于非线性规划问题的方法,适用于不同类型的问题。本文将利用起解决经济调度问题,感兴趣的可以了解一下
内容介绍双Y轴图简介实现思路实现代码样式一样式二双Y轴图简介双Y轴图顾名思义就是在一个图里有两个Y轴。这种图形主要用来展示两个因变量和一个自变量的关系并且两个因变量的数值单位还不同。如我们想要展示不同
这篇文章主要分享的是Python日志模块logging的使用方法总结,ogging模块默认级别是WARNING,意味着只会追踪该级别以上的事件,除非更改日志配置,想了解更多相关资料的小伙伴可以参考下面文章内容
这篇文章主要介绍了基于Pygame实现一个画饼图游戏,可以根据键盘上输入不同的数字,将圆分割成不同的几个部分,每部分用不同的颜色来实现。需要的朋友可以参考一下
反射即想到4个内置函数分别为:getattr、hasattr、setattr、delattr 获取成员、检查成员、设置成员、删除成员classDog(object):def__init__
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008