What Is The Difference between Iterable and Subscriptable in Python?

Question
You have seen messages when coding in Python about iterable and subscriptable. What is the difference between these two?

Answer
A subscriptable does not necessarily use the iter method, but an iterable always does.

A subscriptable object in Python leverages the getitem() method, but it may or may not use the iter method.

To learn more, see these links: StackOverflow, Programiz.com, and w3schools.com

Leave a comment

Your email address will not be published. Required fields are marked *