Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
What Is a Tuple? | Other Data Types
Introduction to Python

What Is a Tuple?

A tuple is another data type in Python that can hold multiple values or variables. These values are separated by commas and wrapped in parentheses. At first, it might seem like tuples are pretty similar to lists, but there are some key differences you should be aware of.

The main distinction lies in mutability: lists can be modified, but tuples cannot. You might recall altering a list using the .extend() method. This method isn't available for tuples, meaning once a tuple is set, you can't change its contents without creating a new tuple. Plus, tuples are more efficient in terms of speed and memory usage compared to lists. Given their immutability, tuples are often chosen when dealing with sensitive data.

Let's keep working with the example data we've been using:

Note

You can also transform an iterable object into a tuple with the tuple() function.

Все було зрозуміло?

Секція 4. Розділ 6
course content

Зміст курсу

Introduction to Python

What Is a Tuple?

A tuple is another data type in Python that can hold multiple values or variables. These values are separated by commas and wrapped in parentheses. At first, it might seem like tuples are pretty similar to lists, but there are some key differences you should be aware of.

The main distinction lies in mutability: lists can be modified, but tuples cannot. You might recall altering a list using the .extend() method. This method isn't available for tuples, meaning once a tuple is set, you can't change its contents without creating a new tuple. Plus, tuples are more efficient in terms of speed and memory usage compared to lists. Given their immutability, tuples are often chosen when dealing with sensitive data.

Let's keep working with the example data we've been using:

Note

You can also transform an iterable object into a tuple with the tuple() function.

Все було зрозуміло?

Секція 4. Розділ 6
some-alt