
In Python, iterable and iterator have specific meanings.
An iterable is an object that has an iter method which returns an iterator, or which defines a getitem method that can take sequential indexes starting from zero (and raises an IndexError when the indexes are no longer valid). So an iterable is an object that you can get an iterator from.
An iterator is an object with a next (Python 2) or next (Python 3) method.
Whenever you use a for loop, or map, or a list comprehension, etc. in Python, the next method is called automatically to get each item from the iterator, thus going through the process of iteration.
A good place to start learning would be the iterators section of the tutorial and the iterator types section of the standard types page. After you understand the basics, try the iterators section of the Functional Programming HOWTO.
design function
- do one job
- DRY
- generally
multiple environments in one diagram
- the names are looked up in the current environment and from the earlest frame to its parent
- the function returns to the frame where it was called




近期评论