Calling methods surrounded by __ in Python
我在读一本关于python的书,上面说当你调用
但是,列出的字符串方法之一是
为什么可以调用这些方法中的一些,如
这本书不正确。您可以直接调用
大多数代码不应该直接调用它们,而是让Python来调用它们。例如,使用
语言保留所有这些名称供自己使用;请参阅参考文档中的保留标识符类:
System-defined names. These names are defined by the interpreter and its implementation (including the standard library). Current system names are discussed in the Special method names section and elsewhere. More will likely be defined in future versions of Python. Any use of
__*__ names, in any context, that does not follow explicitly documented use, is subject to breakage without warning.