首页 > 编程语言 > 详细

python的__getitem__

时间:2019-02-10 23:39:12      阅读:236      评论:0      收藏:0      [点我收藏+]
#这个方法返回与指定键相关的值。对序列来说,键应该是0~n-1的整数,其中n为序列的长度。对映射来说,键可以是任何类型。
class Test(object):
    def __init__(self):
        self.change = {"python": "this is python"}
        self.list = [hello, 2019]

    def __getitem__(self, item):
        return self.list[item]
        # return self.change[item]

t = Test()
print(t[1])
# print(t[‘python‘])

 

python的__getitem__

原文:https://www.cnblogs.com/Stephen-Qin/p/10360582.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!