W3Schools Python Zip Function Tutorial Guide

Logan Jul 13, 2026

The `zip()` function in Python is a ubiquitous tool for iterating over multiple iterables (like lists, tuples, etc.) simultaneously. It's an essential aspect of Python's powerful and concise syntax, making it a must-know for any Python programmer.

Python Tip: Use zip() Like a Pro 🐍
Python Tip: Use zip() Like a Pro 🐍

The `zip()` function takes in any number of iterables, bundles their corresponding elements together as tuples, and returns a zip object. This zip object can be iterator over, allowing us to unpack the bundled elements one by one.

an image of what is zip function in python?
an image of what is zip function in python?

Understanding the `zip()` Function

The `zip()` function is incredibly versatile and can be used in a variety of ways. Let's dive deeper into its functionality and explore some use cases.

5 Python Tricks That Will Save You Hours of Coding
5 Python Tricks That Will Save You Hours of Coding

At its core, `zip()` marries elements from multiple iterables into a singular, composite object. By iterating over this object, we can access the bundled elements one by one, each representing a combined, coordinated value from the original iterables.

Zipping Lists

20 Python Functions You Should Know
20 Python Functions You Should Know

One of the most common uses of `zip()` is to combine corresponding elements from two or more lists. Let's say we have two lists - one of fruits and one of their counts. We can combine them into a single list of tuples using `zip()`:

fruits = ["apple", "banana", "cherry"]
counts = [10, 5, 20]
zipped = list(zip(fruits, counts)) # zipped becomes [('apple', 10), ('banana', 5), ('cherry', 20)]

Zipping with Different Iterables

Learn Python Zip Function with Syntax and Examples - TechVidvan
Learn Python Zip Function with Syntax and Examples - TechVidvan

You can use `zip()` with any iterable, not just lists. Tuples, sets, strings, you name it! Let's consider another example, where we want to combine the characters of a string with their ASCII values:

string = "hello"
ascii_values = [ord(c) for c in string]
zipped = list(zip(string, ascii_values)) # zipped becomes [('h', 104), ('e', 101), ('l', 108), ('l', 108), ('o', 111)]

Unzipping in Python

a black background with white text that says zip with uneven lists if the lists are of une equal length,zip will stop when the shortest list is exhausted
a black background with white text that says zip with uneven lists if the lists are of une equal length,zip will stop when the shortest list is exhausted

While `zip()` is great for combining iterables, sometimes we need to do the opposite - separate a list of tuples into original lists. Python provides an `unzip()` function for this purpose:

list1, list2 = zip(*zipped) # list1 becomes ['h', 'e', 'l', 'l', 'o']; list2 becomes [104, 101, 108, 108, 111]

an info sheet with text describing how to use the code for each element in this project
an info sheet with text describing how to use the code for each element in this project
an image of two lists with the text, 2 unzipping lists and 3 random lists
an image of two lists with the text, 2 unzipping lists and 3 random lists
a black screen with text that reads, 3 types of python functions in the same language
a black screen with text that reads, 3 types of python functions in the same language
Python range() function
Python range() function
Pi in Python β€” How It Works?
Pi in Python β€” How It Works?
10 Fun Python Exercises for Kids
10 Fun Python Exercises for Kids
Best Free Websites to Learn Python for Beginners
Best Free Websites to Learn Python for Beginners
a computer screen with the text example 4 using zip with dictionaries
a computer screen with the text example 4 using zip with dictionaries
Python Learning Path for Beginners 2026 πŸš€
Python Learning Path for Beginners 2026 πŸš€
Python Programming, Python
Python Programming, Python
Machine Learning with Python Tutorial
Machine Learning with Python Tutorial
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
30-Day Python Learning Plan for Beginners | Complete Python Roadmap to Learn Coding Fast
πŸ“˜ Python Functions Made Easy
πŸ“˜ Python Functions Made Easy
Python Exit For Loop with Example Programs
Python Exit For Loop with Example Programs
7 Cool Python Projects for Kids to Try!
7 Cool Python Projects for Kids to Try!
Triumph Found! Superior Python, Java, JavaScript Help: Quest Ended – Order for Victorious Ventures!
Triumph Found! Superior Python, Java, JavaScript Help: Quest Ended – Order for Victorious Ventures!
PYTHON BASICS
PYTHON BASICS
Python For Everything – Top Libraries & What They’re Used For
Python For Everything – Top Libraries & What They’re Used For
How to use while loops in Python
How to use while loops in Python

In this function, `*args` syntax is used to unpack the tuples from `zipped`. Alternatively, `itertools` module's `zip_longest()` function can be used to handle iterables of unequal length, filling in `None` values where needed.

Using `zip_longest()` with `fillvalue` Parameter

Let's illustrate this with an example. Imagine we have two lists of different lengths. We can use `zip_longest()` to zip them together, providing a 'fillvalue' to replace missing values:

from itertools import zip_longest
list1 = [1, 2, 3, 4, 5, 6, 7]
list2 = [10, 20, 30]
zipped = list(zip_longest(list1, list2, fillvalue=0)) # zipped becomes [(1, 10), (2, 20), (3, 30), (4, 0), (5, 0), (6, 0), (7, 0)]

In conclusion, the `zip()` function is an invaluable tool for Python developers. From combining corresponding elements from multiple lists to zipping with different iterables and unzipping back to lists, it's a multi-tool for your Python toolbox.