Skip to content
Worked Examples · Example 3.3

Q.#create a tuple tuple1
tuple1 = (10, 20, "Apple", 3.4, 'a')
#print the elements of the tuple tuple1
print(tuple1)
(10, 20, "Apple", 3.4, 'a')

Yanam BieapTextbookSubjective· 2mImportance★★★★★est
12% · 3/25 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

This code demonstrates how to create a tuple in Python, which is an ordered, immutable collection of items, and then print its contents.

In Python, a tuple is a fundamental data structure used to store an ordered collection of items. The key characteristic that distinguishes tuples from lists is their immutability: once a tuple is created, its elements cannot be changed, added, or removed. This makes tuples suitable for storing data that should remain constant throughout the program's execution.

Tuples are defined by enclosing the elements in parentheses () and separating them with commas. They can hold items of different data types, such as integers, floating-point numbers, and strings, all within the same tuple.

Note

Key properties of tuples:

  • Ordered: The elements maintain their insertion order.
  • Immutable: Once created, the elements cannot be modified.
  • Heterogeneous: Can store items of different data types.
  • Indexed: Elements can be accessed using integer indices, starting from 0.

The provided code first creates a tuple named tuple1 and then prints its contents to the console.

#create a tuple tuple1
tuple1 = (10, 20, "Apple", 3.4, 'a')

#print the elements of the tuple tuple1
print(tuple1)

Explanation of Key Lines

  1. tuple1 = (10, 20, "Apple", 3.4, 'a')
    • This line creates a tuple and assigns it to the variable tuple1.
    • The parentheses () indicate that it is a tuple. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.