"__method__"与"__method__"之间的区别和“方法" [英] Difference between "__method__" and "method"
问题描述
__method__
,method
和_method__
有什么区别?
是否出于某种或某些随机原因,人们认为__doc__
应该是正确的,而不是doc
.是什么让一种方法比另一种更特别?
Is there any or for some random reason people thought that __doc__
should be right like that instead of doc
. What makes a method more special than the other?
推荐答案
-
__method
:私有方法. -
__method__
:特殊的Python方法.它们这样命名,以防止名称冲突. 在此页面上查看这些特殊方法的列表. -
_method
:这是 Python样式中建议的受保护方法的命名约定指南. __method
: private method.__method__
: special Python method. They are named like this to prevent name collisions. Check this page for a list of these special methods._method
: This is the recommended naming convention for protected methods in the Python style guide.-
_single_leading_underscore
:内部使用"指示器较弱.例如.from M import *
不会导入名称以下划线开头的对象. _single_leading_underscore
: weak "internal use" indicator. E.g.from M import *
does not import objects whose name starts with an underscore.
从样式指南:
single_trailing_underscore_
:按惯例用于避免与
Python关键字,例如
single_trailing_underscore_
: used by convention to avoid conflicts with
Python keyword, e.g.
Tkinter.Toplevel(master, class_='ClassName')
__double_leading_underscore
:命名类属性时,调用名称
修改(在类FooBar
中,__boo变为_FooBar__boo
;请参见下文).
__double_leading_underscore
: when naming a class attribute, invokes name
mangling (inside class FooBar
, __boo becomes _FooBar__boo
; see below).
__double_leading_and_trailing_underscore__
:魔术"对象或
位于用户控制的名称空间中的属性.例如. __init__
,
__import__
或__file__
.千万不要发明这样的名字;只使用它们
__double_leading_and_trailing_underscore__
: "magic" objects or
attributes that live in user-controlled namespaces. E.g. __init__
,
__import__
or __file__
. Never invent such names; only use them
as documented.
这篇关于"__method__"与"__method__"之间的区别和“方法"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!