Python does not support formal access control, but names beginning with a single underscore are conventionally akin to protected, while names beginning with a double underscore (other than special methods) are akin to private.
Python 不支持正式的访问控制,但以单下划线开头的名称通常类似于 protected
self._apr = apr
,而以双下划线开头的名称(特殊方法除外)类似于 private。
super().__init__ (customer, bank, acnt, limit)
def __next__(self):
本文探讨了Python中关于访问控制的非正式约定,指出单下划线前缀的变量类似protected,双下划线前缀(非特殊方法)则类似private。示例中展示了如何使用`_apr`和`__next__`方法遵循这些约定。
342

被折叠的 条评论
为什么被折叠?



