- BASICS
- Statements
- Operators
- Functions
- Incremental
- Errors
- FUNCTIONS
- Recursion
- Objects
- Lambda
- STRINGS
- Immutable
- Raw Strings
- Validation
- Config
- Security
- CLASS
- Definition
- Attributes
- Functional
- Methods
- COLLECTIONS
- Lists
- Dictionaries
- Efficiency
- Tree
-
Iterator
- Tuples
- References
- STORAGE
- Files
- Databases
- Pipes
- With Open
- Shelve
- Zip
- Csv
- Json
Iterable
An iterable object returns an iterator when passed to the build-in function iter()
A = [1, 2, 3]
I = iter(A) # iterator
print(next(I)) # 1
print(next(I)) # 2
print(next(I)) # 3
try:
print(next(I))
except StopIteration:
print("StopIteration")
Questions and answers
When we pass an object to iter() function we get an:
- a) iterator object
- b) iterable
A loop implicitly creates an iterator
- a) true
- b) false, it only needs more memory