Back to Lesson

Tuple Mutability Try-Catch

Attempt to modify an immutable sequence and catch the resulting error gracefully.

Instructions

  • Given the tuple
    config = ("dark_mode", "1080p")
  • In a
    try
    block, attempt to change the first element (
    config[0]
    ) to
    "light_mode"
  • In the
    except TypeError
    block, print
    "Cannot modify tuple"
    .
main.py
main.py