![]() |
VOOZH | about |
Python iter() method is a built-in method that allows to create an iterator from an iterable. An iterator is an object that enables us to traverse through a collection of items one element at a time. Let’s start by understanding how iter() works with a simple example.
10 20
Table of Content
Syntax of
iter()methoditerator = iter(iterable)
Parameters
iterable: Any object capable of returning its elements one at a time. Examples include lists, tuples, dictionaries, and strings.Return Type
- Returns an iterator object that can be used with the
next()function or aforloop to access the elements sequentially.
iter() Methoditer() with StringP y
iter() with Dictionarya b c
iter() with Callable and Sentinel5 5