About 18,100,000 results
Open links in new tab
  1. python - How to build a basic iterator? - Stack Overflow

    Iterator objects in python conform to the iterator protocol, which basically means they provide two methods: __iter__() and __next__(). The __iter__ returns the iterator object and is implicitly …

  2. Python Iterators - W3Schools

    Create an Iterator. To create an object/class as an iterator you have to implement the methods __iter__() and __next__() to your object. As you have learned in the Python Classes/Objects …

  3. Iterators and Iterables in Python: Run Efficient Iterations

    Jan 6, 2025 · Python iterators are objects with .__iter__() and .__next__() methods. Iterables are objects that can return an iterator using the .__iter__() method. Generator functions use the …

  4. Iterators in Python - GeeksforGeeks

    Dec 16, 2024 · Creating a custom iterator in Python involves defining a class that implements the __iter__() and __next__() methods according to the Python iterator protocol. Define the Class: …

  5. Python Iterators (With Examples) - Programiz

    Using an iterator method, we can loop through an object and return its elements. Technically, a Python iterator object must implement two special methods, __iter__() and __next__(), …

  6. How to Use the Python iter() Method? - AskPython

    May 20, 2020 · We can use the iter() function to generate an iterator to an iterable object, such as a dictionary, list, set, etc. The basic syntax of using the Python iter() function is as follows: This …

  7. Python Iterators with examples: Creation and Usage Guide

    Aug 23, 2024 · In Python, an iterator is an object that can be iterated (looped) upon. An iterator returns one element at a time from a sequence, like a list, tuple, or string. Understanding …

  8. syntax - Python: Make class iterable - Stack Overflow

    Mar 25, 2011 · You can make class members iterable within just a single line. Despite the easy and compact code there are two mayor features included, additionally: Type checking allows …

  9. Python Iterator: Example Code and How it Works

    Jun 24, 2024 · I’ll demonstrate with a simple iterator class that returns even numbers. As we’ve learned, we need to implement __iter__ and __next__. We’ll do this in one single class to keep …

  10. Python Iterators - Python Geeks

    We can create iterators by using a function called iter(). It takes one iterable argument and returns an iterator-type object. This object is called the iterator. Syntax. iter(iterable) Example of …

  11. Some results have been removed
Refresh