VOOZH about

URL: https://www.geeksforgeeks.org/python/python-iter-method/

⇱ Python iter() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python iter() method

Last Updated : 11 Dec, 2024

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.


Output
10
20

Syntax of iter() method

iterator = 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 a for loop to access the elements sequentially.

Examples of iter() Method

Using iter() with String


Output
P
y

Using iter() with Dictionary


Output
a
b
c

Using iter() with Callable and Sentinel


Output
5
5
Comment