What Is Tuple in Python With Example - Complete Guide

Logan Jul 13, 2026

In Python, a tuple is a collection type that is ordered and immutable. It is similar to a list, with the key difference being that tuples cannot be changed once they are created. This synthesizes them for situations where data should not be altered. Let's explore this data structure with examples to illustrate its functionality.

Are Tuples Mutable In Python Explained With Examples
Are Tuples Mutable In Python Explained With Examples

Tuples are defined using parentheses, with elements separated by commas. They can hold different data types, including integers, floats, strings, and even other tuples. Here's a simple example:

Tuples in Python - UnicMinds
Tuples in Python - UnicMinds

Tuples vs Lists

Before delving deeper into tuples, let'squickly compare them with lists, another common collection type in Python.

Tuples Explained for Beginners | Python Tuple Tutorial
Tuples Explained for Beginners | Python Tuple Tutorial

While both tuples and lists can hold multiple values, lists are mutable, meaning their content can be changed, whereas tuples are immutable, making them more suitable for protecting against unintended modifications.

Tuples Are Immutable

the differences between list and tuple in an appetizing game, which is also available
the differences between list and tuple in an appetizing game, which is also available

Here's an example demonstrating the immutability of tuples:

```python my_tuple = (1, 2, 3) my_tuple[0] = 0 # This will raise a TypeError ```

Creating Tuples

Python Tuples
Python Tuples

Tuples can be created in several ways:

  1. Using parentheses: (1, 2, 3)
  2. Without parentheses, Python automatically creates a tuple: 1, 2, 3
  3. With a single element: (1,), the trailing comma is mandatory to differentiate from a simple integer

Tuple Methods and Operations

Tuples in Python; and how to create and access items form  it | Python Programming
Tuples in Python; and how to create and access items form it | Python Programming

The most common operations on tuples are indexing and slicing, just like lists. Tuples also have several built-in methods, although fewer than lists due to their immutable nature.

Indexing and Slicing

Python Collection Data Types | Lists, Tuples, Sets & Dictionaries Explained
Python Collection Data Types | Lists, Tuples, Sets & Dictionaries Explained
TUPLES vs LISTS
TUPLES vs LISTS
Tuple in Python (with Examples) - Scientech Easy
Tuple in Python (with Examples) - Scientech Easy
What is Python iter Function How to Use it With Examples
What is Python iter Function How to Use it With Examples
Coding For Beginners Python - Learn the Basics - Collections
Coding For Beginners Python - Learn the Basics - Collections
Python Variables Tutorial for Beginners 🚀
Python Variables Tutorial for Beginners 🚀
an image of a computer screen with the words python and numbers on it in different languages
an image of a computer screen with the words python and numbers on it in different languages
Python Tuple Sort | How to Sort Python Tuples? | Sorting Tuples ⋆ IpCisco
Python Tuple Sort | How to Sort Python Tuples? | Sorting Tuples ⋆ IpCisco
Python Tuples Explained for Beginners (Day 16)
Python Tuples Explained for Beginners (Day 16)
Python Tuples
Python Tuples
Python Tutorial for Beginners 4: Lists, Tuples, and Sets
Python Tutorial for Beginners 4: Lists, Tuples, and Sets
Python Cheat Sheet for Beginners
Python Cheat Sheet for Beginners
a screenshot of some type of text that reads taming data with tuples
a screenshot of some type of text that reads taming data with tuples
a diagram that shows the different types of python tuples and how to use them
a diagram that shows the different types of python tuples and how to use them
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
Python Data Structures Cheat Sheet for Beginners (Lists, Tuples, Sets & Dictionaries)
Tuples in Python 💻
Tuples in Python 💻
Shortcut to learn Python.[Cheatsheet]
Shortcut to learn Python.[Cheatsheet]
an image of what is zip function in python?
an image of what is zip function in python?
Python Lists in Python Programming
Python Lists in Python Programming
the cover of collection data types in python, with an image of numbers and symbols
the cover of collection data types in python, with an image of numbers and symbols

Tuples can be indexed and sliced, providing great flexibility for accessing and manipulating data:

```python my_tuple = (1, 2, 3, 4, 5) print(my_tuple[0]) # Output: 1 print(my_tuple[0:3]) # Output: (1, 2, 3) ```

Tuple Methods

Some useful tuple methods include:

  • len(tuple) - returns the number of elements in the tuple
  • tuple.count(value) - returns the number of times a specified value appears in the tuple
  • tuple.index(value) - returns the index of the first occurrence of a specified value

Tuples are a powerful tool in Python, offering a secure way to group and manage data. They are extensively used in functions that should not alter their arguments, and when working with unpacking and data structures like dictionary keys. By appreciating the benefits of immutability, you can make your Python code more robust and maintainable. Happy coding!