פייתון/פייתון גרסה 3/iterables: הבדלים בין גרסאות בדף

תוכן שנמחק תוכן שנוסף
Mathreturn (שיחה | תרומות)
שורה 29:
<source lang = "python">
 
# list is an iterable, which doesn't have a iterator therefor we can't use next on it:
lst = range(2)
>>> lst = range(2)
>>> next(lst)
Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
next(lst)
TypeError: 'range' object is not an iterator
 
# but if we use the function iter:
 
iterator_steps = iter(lst)