Python iter() method Last Updated : 11 Dec, 2024 Comments Improve Suggest changes Like Article Like Report 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. Python a = [10, 20, 30, 40] # Convert the list into an iterator iterator = iter(a) # Access elements using next() print(next(iterator)) print(next(iterator)) Output10 20 Table of ContentSyntax of iter() methodExamples of iter() MethodFrequently Asked Questions on iter() MethodSyntax of iter() methoditerator = iter(iterable)Parametersiterable: Any object capable of returning its elements one at a time. Examples include lists, tuples, dictionaries, and strings.Return TypeReturns an iterator object that can be used with the next() function or a for loop to access the elements sequentially.Examples of iter() MethodUsing iter() with String Python # Convert string to iterator s = "Python" iterator = iter(s) print(next(iterator)) print(next(iterator)) OutputP y Using iter() with Dictionary Python d = {'a': 1, 'b': 2, 'c': 3} iterator = iter(d) for key in iterator: print(key) Outputa b c Using iter() with Callable and Sentinel Python # Generate numbers until sentinel value is encountered import random iterator = iter(lambda: random.randint(1, 5), 3) for num in iterator: print(num) Output5 5 Comment More infoAdvertise with us Next Article Python iter() method manjeet_04 Follow Improve Article Tags : Python python-list Python-Built-in-functions python-list-functions python +1 More Practice Tags : pythonpythonpython-list Similar Reads Python List methods Python list methods are built-in functions that allow us to perform various operations on lists, such as adding, removing, or modifying elements. In this article, weâll explore all Python list methods with a simple example.List MethodsLet's look at different list methods in Python:append(): Adds an 3 min read Python | getattr() method The getattr() method in Python returns the value of a named attribute of an object. If the attribute is not found then it returns the default value provided. If no default is given and the attribute does not exist then it raises an AttributeError.Python getattr() Method SyntaxSyntax : getattr(obj, k 3 min read Instance method in Python A class is a user-defined blueprint or prototype from which objects are created. Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to 2 min read Python Dictionary Methods Python dictionary methods is collection of Python functions that operates on Dictionary.Python Dictionary is like a map that is used to store data in the form of a key: value pair. Python provides various built-in functions to deal with dictionaries. In this article, we will see a list of all the fu 5 min read Python - __lt__ magic method Python __lt__ magic method is one magic method that is used to define or implement the functionality of the less than operator "<" , it returns a boolean value according to the condition i.e. it returns true if a<b where a and b are the objects of the class. Python __lt__ magic method Syntax S 2 min read Python __add__() magic method Python __add__() function is one of the magic methods in Python that returns a new object(third) i.e. the addition of the other two objects. It implements the addition operator "+" in Python. Python __add__() Syntax Syntax: obj1.__add__(self, obj2) obj1: First object to add in the second object.obj2 1 min read Python __len__() magic method Python __len__ is one of the various magic methods in Python programming language, it is basically used to implement the len() function in Python because whenever we call the len() function then internally __len__ magic method is called. It finally returns an integer value that is greater than or eq 2 min read Python next() method Python's next() function returns the next item of an iterator. Example Let us see a few examples to see how the next() method in Python works. Python3 l = [1, 2, 3] l_iter = iter(l) print(next(l_iter)) Output1 Note: The .next() method was a method for iterating over a sequence in Python 2.  It has 4 min read Python Fire Module Python Fire is a library to create CLI applications. It can automatically generate command line Interfaces from any object in python. It is not limited to this, it is a good tool for debugging and development purposes. With the help of Fire, you can turn existing code into CLI. In this article, we w 3 min read String lower() Method in Python lower() method in Python converts all uppercase letters in a string to their lowercase. This method does not alter non-letter characters (e.g., numbers, punctuation). Let's look at an example of lower() method:Pythons = "HELLO, WORLD!" # Change all uppercase letters to lowercase res = s.lower() prin 3 min read Like