Junior — Middle
Can you list examples of immutable data structures in Python?
sobes.tech AI
Answer from AI
In Python, the immutable data structures include:
- tuple — a tuple, its elements cannot be changed after creation.
- str — a string, any operations create a new string, the original remains unchanged.
- frozenset — an immutable set.
- bytes — an immutable sequence of bytes.
Example of using a tuple:
point = (10, 20)
# point[0] = 15 # will cause an error because tuple is immutable