Unused argument warnings can be suppressed by deleting the variables at the beginning of the function. Always include a comment explaining why you are deleting it. “Unused.” is sufficient. For example: defviking_cafe_order(spam: str, beans: str, eggs: str|None=None)->str:delbeans, eggs#...
foo = 1000 # comment long_name = 2 # comment that should not be aligned dictionary = { 'foo' : 1, 'long_name': 2, } 3.7 Shebang 大部分.py文件不需要从#!行来开始.根据PEP-394,程序的主文件应该以#!/usr/bin/python2或#!/usr/bin/python3起始 ...
另一方面, 绝不要描述代码. 假设阅读代码的人比你更懂Python, 他只是不知道你的代码要做什么. # BAD COMMENT: Now go through the b array and make sure whenever i occurs# the next element is i+1 类 如果一个类不继承自其它类, 就显式的从object继承. 嵌套类也一样. Yes:classSampleClass(object)...
# 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 (t...
# BAD COMMENT: Now go through the b array and make sure whenever i occurs # the next element is i+1 类 如果一个类不继承自其它类,就显式的从object继承,嵌套类也一样。 classSampleClass(object): pass classOuterClass(object): classInnerClass(object): ...
In the standard library, non-default encodings should be used only for test purposes or when a comment or docstring needs to mention an author name that contains non-ASCII characters; otherwise, using \x, \u, \U, or \N escapes is the preferred way to include non-ASCII data in string ...
这份文档为主Python发行版中标准库的Python代码提供了编码规范。请参阅相关的信息性PEP,该PEP描述了Python C实现中的C代码的样式指南。 这份文档和PEP 257(文档字符串规范)改编自Guido的原始Python样式指南文章,并加入了Barry样式指南的一些内容[2]。 随着额外的约定的发现和语言本身的变化使过去的约定变得过时,这个样...
这是一位大佬翻译的GooglePython代码风格指南,很全面。可以作为公司的code review 标准,也可以作为自己编写代码的风格指南。希望对你有帮助。 Translator: shendeguize@github Link: https://github.com/shendeguize/GooglePythonStyleGuideCN 本翻译囿于水平,可能有不准确的地方,欢迎指出,谢谢大家 ...
self.user_name =''self.Gender ='male'#comment in wrong identself.active =Falsedeflogin(self, Person): self.user_name=Person.user_name not_used_var =0returnTruedefLogout(self): self.active =Falsedefplace_order(self): place_order()defaction(): ...
Link: https://github.com/shendeguize/GooglePythonStyleGuideCN 本翻译囿于水平,可能有不准确的地方,欢迎指出,谢谢大家 1 背景 Python是谷歌主要使用的动态语言,本风格指导列举了使用Python编程时应该做和不该做的事项(dos & don'ts) 为了帮助你正确地组织代码,我们编写了一个Vim的设置文件.对于Emacs,默认设置即...