2024-04-19 17:00:10 发布
网友
最近,我在看一些Python成语。 我发现了Python中使用的许多协议描述,比如排序(__cmp__,…)或生成器。此外,还有像__hash__这样的方法为每个对象定义(我想)。
__cmp__
__hash__
在网上搜索之后,我还没有找到这些协议和方法的完整列表。 有人能给我一些指针url吗?
最好的参考总是Python Online Documentation,特别是Special method names部分。
交互式Python解释程序也是一个非常有用的工具。试试这些:
>>> dir(object) ['__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] >>> help(object.__class__) >>> help(object.__hash__) >>> help(hash)
最好的参考总是Python Online Documentation,特别是Special method names部分。
交互式Python解释程序也是一个非常有用的工具。试试这些:
相关问题 更多 >
编程相关推荐