首页 > 编程语言 > 详细

python 进阶读书笔记2 -- python魔法函数

时间:2018-06-13 00:44:24      阅读:251      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env python
# -*- coding: utf-8 -*-

class student:
def __init__(self, name_list):
self.student_name_list = name_list

def __getitem__(self, item):
return self.student_name_list[item]


stu = student([‘tom‘, ‘bob‘, ‘jane‘, ])
stu = stu[:2]
l = len(stu)
for student_name in stu:
‘‘‘
1.寻找实例的__iter__方法
2.调用__getitem__方法,直到抛出异常
‘‘‘
print(student_name)

 

python 进阶读书笔记2 -- python魔法函数

原文:https://www.cnblogs.com/wanghzh/p/9175737.html

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