02, iterator
Objects that can be iterated:
Internal containing __iter__ follows an iterative protocol
# Print (dir (' 123 ')) # ' __iter__ '# print (' __iter__ ' in Dir ([1, 2, 3])# Print (' __iter__ ' in dir ({' name ': ' Alex '})# print (' __iter__ ' in dir ({' name '})#) # Print (' __iter__ ' in Dir ((1, 2, 3))# print (' __iter__ ' in Dir (1)) # False# c15> print (' __iter__ ' in Dir (True)) # False
iterator: An iterative object. __iter__ () can be converted to an iterator that satisfies the iterator protocol
internally containing __iter__ and __next__
determine if the __iter__ is not in Dir (object)
isinstance ()
save memory.
inertia mechanism.
unidirectional irreversible.
mechanism for the FOR loop:
while
Pass
can iterate over objects
iterators
difference between the two
simulating for loop mechanism
03, Generator
is essentially an iterator, built with Python code.
Generator Definition
the builder's notation
yield
Send
Python learning D13 iterator builder list deduction builder expression