Python3关与迭代器next()使用为__next__()的一点注意事项
来源:互联网 发布:淘宝拍摄摄影软件 编辑:程序博客网 时间:2024/06/03 18:23
class Fibs: def __init__ (self): self.a =0 self.b =1 def next(self): self.a , self.b = self.b, self.a+self.b return self.a def __iter__(self): return self关于如上Python2 代码中迭代器的使用,引用时用*.next()的方式在Python3中不再有效,而是会报错:
Traceback (most recent call last): File "<pyshell#17>", line 1, in <module> it.next()AttributeError: 'list_iterator' object has no attribute 'next'正确改进为:
class Fibs: def __init__ (self): self.a =0 self.b =1 def __next__(self): self.a , self.b = self.b, self.a+self.b return self.a def __iter__(self): return self以next(it)的形式进行引用
0 0
- Python3关与迭代器next()使用为__next__()的一点注意事项
- python迭代器:next( ),__next__( ), iter()
- 关与自己的一点声明!
- CComboBox使用的一点注意事项
- ioctl的一点使用注意事项
- 生成器与__next__关系
- Python3与Python2版本的一点区别
- 在Linux中使用STL迭代器的一点注意事项
- python2与python3迭代器的使用
- python2.7与python3中print的一点不同之处
- python3之IDLE使用注意事项
- TabHost的一点注意事项
- python3之import和reload的使用注意事项
- python类中的__iter__, __next__与built-in的iter()函数举例
- python之__iter__函数与__next__函数
- 使用ftok获取ipc的key值的一点注意事项
- kernel workqueue 一点使用注意事项
- 关于Java开发中使用Oracle数据库的一点注意事项
- Linux笔记--4 -- GDB和makefile
- matlab学习笔记 struct函数
- glCullFace函数
- hadoop环境配置过程中可能遇到问题的解决方案
- 微信公众平台开发者原理图解
- Python3关与迭代器next()使用为__next__()的一点注意事项
- POJ 1922 Ride to School
- mysql导出sql插入报错
- 大四了!家庭压力,想找个男朋友!!
- cas之soo单点登录初步探究
- web服务端技术概述之高性能技术
- 排序算法 c语言
- java线程安全总结
- Java 线程与并发研究系列一Executor简介与使用