Python

Python Menu

Python

Python zip() Function - Definition, Syntax, Parameters, Examples

Definition

The zip() function returns a zip object, which is an iterator of tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together etc.

If the passed iterators have different lengths, the iterator with the least items decides the length of the new iterator.

Syntax

zip(iterator1, iterator2, iterator3 ...)

Parameters

Parameter Description
iterators Iterator objects that will be joined together

Examples

boys = ("Ivan", "Mark", "Mike") girls = ("Marie", "Sarah", "Cindy") students = zip(boys, girls) print(students)

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods