A tuple is an ordered sequence of elements that is immutable. Tuples are syntactically constructed using parentheses ( ) (e.g., device_creds = ('root', 'Juniper123')) or via the tuple() factory constructor. Once instantiated, the length and element references within a tuple cannot be altered, appended, deleted, or reassigned; attempting an assignment such as my_tuple[0] = 'new' raises a TypeError: 'tuple' object does not support item assignment. Because of their immutability, tuples are frequently used to store fixed records or function return values and can serve as keys in dictionaries (provided their contents are hashable). Square brackets are reserved for lists, which are mutable. Hence, statements C and D correctly define tuples.
[Reference: JNCIA-DevOps Study Guide — Python Data Structures: Tuples, Sequences, and Hashability., ]
Submit