全面的Python协议/接口列表 [英] Comprehensive list of Python protocols/interfaces

查看:162
本文介绍了全面的Python协议/接口列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我在看一些Python习语。
我发现Python中使用的协议有很多描述,例如排序( __ cmp __ ,...)或生成器。此外,还有像 __ hash __ 这样的方法,它们是为每个对象定义的(我想)。

Lately, I was looking at some Python idioms. I found many descriptions of protocols used in Python, such as the ordering (__cmp__, ...) or generators. Besides, there are also methods like __hash__ which are defined for every object (I suppose).

经过一些搜索在互联网上,我还没有找到这些协议和方法的完整列表。
任何人都可以给我一些指针网址吗?

After some search on the internet, I haven't found a comprehensive list of these protocols and methods. Can anyone give me some pointers URLs?

推荐答案

你最好的参考是永远的成为 Python在线文档,特别是关于特殊方法名称

Your best reference is always going to be the Python Online Documentation, specifically the section on Special method names.

交互式Python解释器是一个非常有用的工具,太。尝试其中一些:

The interactive Python interpretor is a very useful tool, too. Try some of these:

>>> 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协议/接口列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆