Python Learning D13 iterator Generator list deduction builder expression

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.