Learn Before
Concept
Tuple
- A tuple is a data structure that can store items within a single variable.
- The items in a tuple are ordered (indexed) and are immutable (cannot be changed).
- Tuples can have duplicate items.
- To create a tuple, surround items (separated by commas) with parentheses. Ex:
tuple = ('apple', 34, 'banana')
- To access an element inside a tuple, use the tuple name along with square brackets and the desired index. Ex:
tuple[1] # access tuple index 1, which is 34.
0
2
Updated 2025-10-06
Contributors are:
Who are from:
Tags
Python Programming Language
Data Science
Foundations of Large Language Models Course
Computing Sciences
Learn After
Tuple Operations
Tuple Reference
A programmer writes the following code snippet to update a collection of user roles. What will be the result when this code is executed?
user_roles = ('viewer', 'commenter', 'editor', 'admin') user_roles[1] = 'contributor' print(user_roles)Choosing the Right Data Structure for Constants
Choosing an Appropriate Data Structure