Skip to content

Instantly share code, notes, and snippets.

@huangzhuolin
Last active June 20, 2018 08:49
Show Gist options
  • Save huangzhuolin/4db7e9f7e4c08731571eaa7dc8219a9c to your computer and use it in GitHub Desktop.
Save huangzhuolin/4db7e9f7e4c08731571eaa7dc8219a9c to your computer and use it in GitHub Desktop.
[python iterable, iterator and generator function] #python

differences between iterables and iterators

iterables have an __iter__ method that instantiates a new iterator every time. iterators implement a __next__ method that returns individual items, and an __iter__ method that returns self.

Therefore, iterators are also iterable, but iterables are not iterators.

generator function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment