Python Tuple Declaration: Methods & Examples
In Python, you can declare a tuple using either of the following two methods:
- Use parentheses ():
- my_tuple contains the following elements: 1, 2, 3, ‘a’, ‘b’, ‘c’
- Use commas, and optional parentheses () to enclose:
- my_tuple contains the values 1, 2, 3, ‘a’, ‘b’, and ‘c’.
You can create a tuple containing multiple elements using any method you choose. Tuples are immutable data structures, meaning once created, the elements within a tuple cannot be modified, added, or deleted. Tuples are typically used to store immutable collections of data for passing and referencing values within a program.