社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如果没有正常函数的sentinel值,Python iter函数将无法工作

Harsh Sharma • 4 年前 • 562 次点击  

这里我定义了一个正常函数:

def abc():
  return 1

for i in iter(abc):
  print i

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'function' object is not iterable

但现在当我用哨兵的时候,它起作用了。

 for i in iter(abc, ''):
  print i

1
1
1
1
1
1
...

你知道为什么会发生上述行为吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52913
 
562 次点击  
文章 [ 2 ]  |  最新文章 4 年前