如何在python中创建自定义列表类? [英] How would I create a custom list class in python?

查看:291
本文介绍了如何在python中创建自定义列表类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Python编写一个自定义列表类(将其称为MyCollection),最终可以在其中调用:

I would like to write a custom list class in Python (let's call it MyCollection) where I can eventually call:

for x in myCollectionInstance:
    #do something here

我该怎么做呢?是我必须扩展某些类,还是必须重写任何功能?

How would I go about doing that? Is there some class I have to extend, or are there any functions I must override in order to do so?

推荐答案

Python语言参考,第3.4.6节模拟容器类型"

这篇关于如何在python中创建自定义列表类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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