Python中Class的编码风格(Styling Classes)

Class names should be written in CamelCase. To do this, capitalize the first letter of each word in the name, and don’t use underscores. Instance and module names should be written in lowercase with underscores between words.

类名应该采用大驼峰规则,每个单词的首字母大写且不要使用下划线。实例和模块名应该小写且单词之间用下划线连接。

Every class should have a docstring immediately following the class definition. The docstring should be a brief description of what the class does. Each module should also have a docstring describing what the classes in a module can be used for.

对于每个类,都应在类的定义后面,简要描述类的功能。每个模块也应该包含相应的解释说明,对于模块中的类的功能进行整体说明。

You can use blank lines to organize code, but don’t use them excessively. Within a class you can use one blank line between methods, and within a module you can use two blank lines to separate classes.

你可以使用空行来组织代码,但是不要滥用。在一个类中,不同方法之间空一行;在一个模块里,不同类之间空两行。

If you need to import a module from the standard library and a module that you wrote, place the import statement for the standard library module first. Then add a blank line and the import statement for the module you wrote. In programs with multiple import statements, this convention makes it easier to see where the different modules used in the program come from.

如果你要调用标准库和自己写的模块,请先import标准库,然后空一行import自己的库。这种做法可以让别人明白程序使用的各个模块来自于哪里。

英文内容来自于python crash courses,主要用于个人学习、记录,侵删。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值