#!/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进阶练习--函数
- python编写一个函数、输入n为偶数时_编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函数1/1+1/3+..-吾爱编程网...
- python -- 函数进阶
- python标准库math中计算平方根的函数_16 Python 标准库之 math 模块 - Python 进阶应用教程...
- python(二)进阶之cv2读取视频文件或摄像头,并进行保存帧图像或视频
- Python----魔法函数__len__和__contains__的用法
- 编写函数,求2个正整数的最小公倍数 python
- Python----魔法函数__enter__/__exit__的用法
- Python爬虫从入门到进阶(2)之urllib库的使用
- python编写函数、计算形式如a+aa_编写程序计算a+aa+aaa+aa...a(n个a)之和。要求定义并调用函数fn(a,n),它的功能是返回aa...a(n个a)。例如,fn(3,2)的返回值...