go语言interface接口继承多态示例及定义解析
326
2022-08-30
python_官方编码规范/(函数)文档规范/三引号“““函数说明/注释规范/vscode文档插件
文章目录
python PEP:Style Guide for Python Code
documentation stringsjetBrain IDEA(pycharm)python_pep
introspection
函数文档规范实例:(numpy 风格)vscode python docString:
使用
python PEP:
Guide for Python Code
strings
jetBrain IDEA(pycharm)
Python | IntelliJ IDEA (jetbrains.com)
python_pep
One-line DocstringsOne-liners are for really obvious cases. They should really fit on one line. For example:
def kos_root(): """Return the pathname of the KOS root directory.""" global _kos_root if _kos_root: return _kos_root ...
Notes:
Triple quotes are used even though the string fits on one line. This makes it easy to later expand it.The closing quotes are on the same line as the opening quotes. This looks better for one-liners.There’s no blank line either before or after the docstring.The docstring is a phrase ending in a period. It prescribes the function or method’s effect as a command (“Do this”, “Return that”), not as a description;
e.g. don’t write “Returns the pathname …”.(这个例子中就不是以一个词组结尾的)
The one-line docstring should NOT be a “signature” reiterating the function/method parameters (which can be obtained by introspection).
Don’t do:
def function(a, b): """function(a, b) -> list"""
This type of docstring is only appropriate for C functions (such as built-ins), whereintrospectionis not possible.However, the nature of thereturn valuecannot be determined byintrospection[^introspection],
so it should be mentioned. (返回值的情况无法被推导,您需要在概述中提一下)The preferred form for such a docstring would be something like:
def function(a, b): """Do X and return a list."""
(Of course “Do X” should be replaced by a useful description!)
introspection
Introspection is an ability to determine the type of an object at runtime. Everything in python is an object. Every object in Python may have attributes and methods. By using introspection, we can dynamically examine python objects.
Code Introspection is used for examining the classes, methods, objects, modules, keywords and get information about them so that we can utilize it.
Introspection reveals useful information about your program’s objects.
Python, being a dynamic, object-oriented programming language, provides tremendous introspection support.
Python’s support for introspection runs deep and wide throughout the language.
.They are: 1. type() : This function returns the type of an object.
``` # Python program showing``# a use of type function`` ` `import` `math`` ` `# print type of math``print``(``type``(math))`` ` `# print type of 1 ``print``(``type``(``1``))`` ` `# print type of "1"``print``(``type``(``"1"``))`` ` `# print type of rk``rk ``=``[``1``, ``2``, ``3``, ``4``, ``5``, ``"radha"``]`` ` `print``(``type``(rk))``print``(``type``(rk[``1``]))``print``(``type``(rk[``5``])) ``` **Output:** ```python
Multi-line Docstrings
It is best to list each argument on a separate line. For example:
def complex(real=0.0, imag=0.0): """Form a complex number. Keyword arguments: real -- the real part (default 0.0) imag -- the imaginary part (default 0.0) """ # your codes: if imag == 0.0 and real == 0.0: return complex_zero ......
函数文档规范实例:(numpy 风格)
vscode python docString:
使用
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~