Next

Creating Tuple

  • This lesson explains how to create tuples in Python and store multiple values in an ordered collection.

  • Tuple

    A tuple is a built-in Python data structure used to store multiple items in a single variable.

    • Tuples are ordered

    • Tuples are immutable (cannot be changed after creation)

    • Allow duplicate values

    • Written using parentheses ( )

    Daily Life Example

    Think of a tuple like:

    • Fixed days of the week

    • GPS coordinates (latitude, longitude)

    • RGB color values

    These values should not change once defined.

Basic Tuple Creation

fruits = ("apple", "banana", "mango")
print(fruits)

Tuple with Different Data Types

student = ("Rahul", 21, "Python", True)
print(student)

Tuple Without Parentheses (Packing)

numbers = 10, 20, 30
print(numbers)

Single Element Tuple

value = (5,)
print(value)
  • Wrong Way ❌

    value = (5)   # This is an integer, not a tuple

Using tuple() Constructor

numbers = tuple([1, 2, 3, 4])
print(numbers)

Empty Tuple

empty = ()
print(empty)
Next