Junior — Middle
Can you explain what a data type that can be modified after creation is?
sobes.tech AI
Answer from AI
A data type that can be modified after its creation is called mutable. In Python, such types include, for example, lists (list), dictionaries (dict), sets (set).
This means you can change the contents of the object without creating a new one. For example, adding an element to a list or changing a value by key in a dictionary.
Example:
my_list = [1, 2, 3]
my_list.append(4) # the list has changed, now [1, 2, 3, 4]
Unlike mutable types, there are immutable types, such as strings (str), tuples (tuple), numbers (int), which cannot be changed after creation — any operations create a new object.