Tuples are similar to lists:
Lists | Tuples |
---|---|
mutable | immutable |
use square brackets to identify | use parentheses to identify |
Tuples tend to be faster since they are immutable
Example
sentence = ( "This", "is", "a", "tuple") print(sentence[1]) sentence[3] = "phrase"
An empty tuple:
sentence = ()
- Printer-friendly version
- Log in to post comments
- 121 views