Menu Close

Python zip() function

In this python guide, we are going to learn all about the Python zip() function to return a zip object.
In the previous tutorial, we have seen all about the Python vars() function return dict attribute of the given Object.

Python zip() function

Python zip function is a built-in function that takes zero or more tables and aggregates them and returns them.

zip() function in Python returns a zip object, which is an iterator of tuples, where the first item of each iterator is paired together.

If the iterator has a different length, Then the iterator with the least items decides the length of the new iterator.


The syntax of zip function in Python is:-

zip(iterator 1, iterator 2, iterator 3, iterator 4, ....)


zip function in Python accepts zero or more iterator.

Return Value:

The return value of the zip function is a zip object.


x = [1, 2, 3, 4, 5, 6, 7]
y  = {'a', 'b', 'c'}
z = ('x', 'y', 'z')
result = zip(x, y, z)
for i in result:


(1, 'c', 'x')
(2, 'b', 'y')
(3, 'a', 'z')


In this article, you have learned all about the Python zip function to return the zip object is an iterator of tuples that can be iterate through for loop.
I hope this article will help you. If you like this article, please share and keep visiting for further Python tutorials.

Python built-in functions

For more information:- Click Here

Previous Article
Next Article

Related Posts