Iteration is a general term for taking each item of something, one after another. Any time you use a loop, explicit or implicit, to go over a group of items, that is iteration.

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.

Answer from agf on Stack Overflow
Top answer
1 of 15
679

Iteration is a general term for taking each item of something, one after another. Any time you use a loop, explicit or implicit, to go over a group of items, that is iteration.

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.

2 of 15
430

Here's the explanation I use in teaching Python classes:

An ITERABLE is:

  • anything that can be looped over (i.e. you can loop over a string or file) or
  • anything that can appear on the right-side of a for-loop: for x in iterable: ... or
  • anything you can call with iter() that will return an ITERATOR: iter(obj) or
  • an object that defines __iter__ that returns a fresh ITERATOR, or it may have a __getitem__ method suitable for indexed lookup.

An ITERATOR is an object:

  • with state that remembers where it is during iteration,
  • with a __next__ method that:
    • returns the next value in the iteration
    • updates the state to point at the next value
    • signals when it is done by raising StopIteration
  • and that is self-iterable (meaning that it has an __iter__ method that returns self).

Notes:

  • The __next__ method in Python 3 is spelt next in Python 2, and
  • The builtin function next() calls that method on the object passed to it.

For example:

>>> s = 'cat'      # s is an ITERABLE
                   # s is a str object that is immutable
                   # s has no state
                   # s has a __getitem__() method 

>>> t = iter(s)    # t is an ITERATOR
                   # t has state (it starts by pointing at the "c"
                   # t has a next() method and an __iter__() method

>>> next(t)        # the next() function returns the next value and advances the state
'c'
>>> next(t)        # the next() function returns the next value and advances
'a'
>>> next(t)        # the next() function returns the next value and advances
't'
>>> next(t)        # next() raises StopIteration to signal that iteration is complete
Traceback (most recent call last):
...
StopIteration

>>> iter(t) is t   # the iterator is self-iterable
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-difference-iterable-iterator
Python | Difference between iterable and iterator - GeeksforGeeks
July 11, 2025 - Iterable is an object, that one can iterate over. It generates an Iterator when passed to iter() method. An iterator is an object, which is used to iterate over an iterable object using the __next__() method.
Discussions

I'm somewhat confused about difference between Iterator and Iterable
Iterable can be thought of a designation that says "this class can be iterated over." So for example, HashSet is iterable, but HashSet itself is not an iterator. All that Iterable guarantees is that the class returns a concrete object that implements Iterator. Iterator is the concrete object that you actually use to iterate over the collection. The implementing class controls how to actually traverse the collection. do I just have to return a linked list of some sort (stack/queue)? why not use iterator instead? To reiterate the above, what you are returning is an object that implements Iterable. So yes, you could use a LinkedList or ArrayList because they implement Iterable. If you require more fine-tuned control over the iterator, then you could do something like this: public Iterable solution(){ return new Iterable(){ public Iterator iterator(){ //Return your iterator } } } You will need to create an inner class that implements Iterator and specifies how to actually iterate over all the boards. Look up how to properly implement Iterator, for example . More on reddit.com
🌐 r/javahelp
4
6
November 23, 2017
What is iterators and generators?
I need to understand what is iterator and generators. I looked into YouTube and gone through documents but didn’t get it. What is the purpose, impact and where and when one can use it? Its quite confusing. Please help. More on discuss.python.org
🌐 discuss.python.org
5
0
January 16, 2026
iterator and iterable object, is there a difference?
An iterator is an object which has a __next__ method. An iterable is an object which has a __getitem__ method or has an __iter__ method. You iterate over things with an iterator. You can get an iterator from an iterable. The syntax for x in iterable calls iter(iterable) to get an iterator, then uses that iterator until StopIteration is thrown. Roughly equivalent to this: try: it = iter(iterable) while True: do_thing_with(next(it)) except StopIteration: pass Here's a repl.it with an example of each: https://repl.it/KNPC/0 More on reddit.com
🌐 r/learnpython
12
3
August 17, 2017
Am I the only one who thinks channels are the obvious choice for iterators?
Channels are almost perfect... except the performance is absolute trash for a lot of common iterator cases. Imagine the difference between a conventional for loop incrementing an index, which amortizes to about one processor cycle per loop, versus a channel. To get the next int, we must block the current goroutine, deschedule it, schedule the providing goroutine, have it generate the next value and put it on the channel, deschedule that goroutine, reschedule the consumer, and extract the value from the channel. There's no way to make that fast enough. If you do try to optimize it to remove the cross-goroutine communication, if you work through the process you largely end up with the current proposal. How that is may be subtle and require you to learn about how compilers optimize code internally by representing things as "coroutines" (that's your search engine term) and it's s number of steps, but it is where you end up to a great degree. It's a real pity, the semantics of the channel are pretty good. Edit: See u/assbuttbuttass ' post for resources that will do a lot of the walking through what I meant by "if you try to just optimize channels, you end up pretty close to this proposal anyhow". I was too lazy on my phone at the time to dig them up. Thanks assbuttbuttass. (And thanks for the opportunity to type that sentence.) You could still argue that "the compiler could just optimize down to this" but it's another one of the things that come up so frequently in language design where that seems like it works from the 30,000 foot view but on the ground it just isn't practical. Also, channels do work for cases where the process of generating the next thing and/or consuming the next thing is much, much more expensive than even the expense of all the scheduling. If it's 100ms to handle each things in the iteration, it doesn't matter if it's a microsecond or two to get the next thing so much. Unfortunately, wanting to iterate on int indexes or "the next thing in the hash table", which is pretty cheap on its own, is extremely common and the concurrency expense kills those. More on reddit.com
🌐 r/golang
75
79
June 14, 2024
🌐
Reddit
reddit.com › r/learnpython › iterator and iterable object, is there a difference?
r/learnpython on Reddit: iterator and iterable object, is there a difference?
August 17, 2017 -

My book says "any object with a .next() method is called an iterator, which returns the next value in the range and raises the StopIt exception upon reaching the end".

However, range() function has no next() method, and is however, said to return an iterable object. Thus:

x = range(1, 10)
x.__next__()

returns an error. But, the file iterators:

x = open("file.txt")
x.__next__()

Doesn't return an error. Is there a difference between iterators and iterable objects?

🌐
nvie.com
nvie.com › posts › iterators-vs-generators
Iterables vs. Iterators vs. Generators » nvie.com
September 25, 2014 - An iterable is any object, not necessarily a data structure, that can return an iterator (with the purpose of returning all of its elements). That sounds a bit awkward, but there is an important difference between an iterable and an iterator.
🌐
Real Python
realpython.com › python-iterators-iterables
Iterators and Iterables in Python: Run Efficient Iterations – Real Python
January 6, 2025 - Understanding iterators and iterables in Python is crucial for running efficient iterations. Iterators control loops, allowing you to traverse arbitrary data containers one item at a time. Iterables, on the other hand, provide the data that ...
🌐
ConnectWise
connectwise.com › blog › iterators-and-iterables-in-javascript
Iterators and Iterables in Javascript | ConnectWise
August 11, 2023 - Long story short, think of iterators as a closure that remembers its current state and moves to the next element when we request it.
Find elsewhere
🌐
W3Schools
w3schools.com › python › python_iterators.asp
Python Iterators
They are iterable containers which you can get an iterator from.
🌐
Reddit
reddit.com › r/javahelp › i'm somewhat confused about difference between iterator and iterable
r/javahelp on Reddit: I'm somewhat confused about difference between Iterator and Iterable
November 23, 2017 -

so I know how to implement (e.g public Iterator<E> iterator() { return new ListIterator<E>(//could add first element here); }

but sometimes I see it saying public iterable. what's the difference? I think it is iterator is like you go through it once and you're done but iterable you get back a list that you can go through over and over again?

if it helps the thing I'm having trouble about is this: http://coursera.cs.princeton.edu/algs4/assignments/8puzzle.html

public Iterable<Board> neighbors() 

do I just have to return a linked list of some sort (stack/queue)? why not use iterator<Board> instead?

Edit: I got it, you're returning an object that is iterable itself.

🌐
Zhenyuanlu
zhenyuanlu.com › python-notebook › 06_iterable_iterator_generator
06. Iterable, Iterator, Generator - Python Notebook from Zero to Advanced
So, the primary difference is that while both can be iterated over, an Iterator also keeps track of its current position in the Iterable. While all Iterators are Iterables (because they implement an __iter__() method), not all Iterables are ...
🌐
Python.org
discuss.python.org › python help
What is iterators and generators? - Python Help - Discussions on Python.org
January 16, 2026 - I need to understand what is iterator and generators. I looked into YouTube and gone through documents but didn’t get it. What is the purpose, impact and where and when one can use it? Its quite confusing. Please help.
🌐
Sololearn
sololearn.com › en › Discuss › 1737623 › what-is-the-difference-between-iteration-and-iterator-in-python
What is the difference between iteration and iterator in python
March 26, 2019 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › from
Array.from() - JavaScript | MDN
In fact, the this value can be any constructor function that accepts a single argument representing the length of the new array. When an iterable is passed as items, the constructor is called with no arguments; when an array-like object is passed, the constructor is called with the normalized length of the array-like object.
🌐
Mahsua
blog.mahsua.com › home › python daily asking questions › what is the difference between an iterator and an iterable in python?
What is the difference between an iterator and an iterable in Python?
April 3, 2023 - The key difference between an iterable and an iterator is that an iterable can be looped over multiple times, whereas an iterator can only be iterated over once.
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module2_EssentialsOfPython › Iterables.html
Iterables — Python Like You Mean It
An iterable is any Python object capable of returning its members one at a time, permitting it to be iterated over in a for-loop.
🌐
Trey Hunner
treyhunner.com › 2018 › 02 › python-range-is-not-an-iterator
Python: range is not an iterator
March 1, 2018 - After my Loop Better talk at PyGotham 2017 someone asked me a great question: iterators are lazy iterables and range is a lazy iterable in Python...
🌐
Medium
medium.com › @huasa0115 › python-what-are-iterators-and-iterables-f34ff7b94fe9
[Python] What are iterators and iterables? | by Yi-Ning Huang | Medium
September 25, 2025 - Custom Objects: Any class you define can become iterable by implementing the __iter__() method (or, in some cases, the __getitem__() method).
🌐
npm
npmjs.com › package › gpt-tokenizer
gpt-tokenizer - npm
August 16, 2026 - Same as encodeChat, but uses a generator as output, and may use any iterator as the input chat.
      » npm install gpt-tokenizer
    
Published: Aug 16, 2026
Version: 4.0.0
🌐
All About AI-ML
indhumathychelliah.com › 2020 › 07 › 24 › iterable-vs-iterator-in-python
Iterable vs Iterator in Python – All About AI-ML
January 2, 2022 - Iterators don’t have to be finite.It’s perfectly reasonable to write an iterator that produces an infinite stream of data.