Python Tuple

1) Create a Tuple

Create a tuple with 5 values and print it.


2) Access an Element

Given:

t = (10, 20, 30, 40)

Print the third item.


3) First and Last Element

Given a tuple, print only the first and last elements.


4) Tuple Length

Create a tuple of any data and print its length using len().


5) Negative Index

Given:

t = (1, 2, 3, 4, 5)

Print the last item using negative indexing.


6) Tuple with Different Types

Create a tuple with a string, integer, float, and boolean.


7) Slicing a Tuple

Given:

Print:

  • t[1:4]

  • t[:3]

  • t[2:]


8) Loop Through a Tuple

Loop through a tuple and print each element.


9) Check Membership

Ask user for a number and check if it’s in the tuple.


10) Tuple to List

Convert a tuple to a list and print the list.


11) List to Tuple

Convert a list to a tuple and print the tuple.


12) Count Occurrences

Given:

Use a method to count how many times 2 appears.


13) Index of a Value

Given:

Find and print the index of value 15.


14) Loop with Index

Loop through a tuple and print:


15) Tuple Concatenation

Join:

Print the combined tuple.


16) Repeat Tuple

Create:

Repeat it 3 times and print.


17) Unpack Tuple

Given:

Unpack into x, y, z and print each.


18) Nested Tuple Access

Given:

Print the value 3.


19) Tuple of Strings

Create a tuple of 4 strings and print them in one line separated by commas.


20) Sum of Numeric Tuple

Ask the user for 3 numbers, store them in a tuple, and print the sum.


📝 Notes for Students

  • Tuples are immutable — you cannot change items after creation.

  • Use:

    • len() for length

    • count() to count occurrences

    • index() to find positions

  • Conversion between tuple and list helps when needing mutability.


canvil: 333f6c7d-6876-4f7e-b6ad-1bdb2233f5c1

Last updated