Sobes.tech
Junior — Middle

What features are available in data that can be modified during program execution?

sobes.tech AI

Answer from AI

Data that can be modified during program execution are called mutable. In Python, such types include, for example, lists (list), dictionaries (dict), sets (set).

Features of mutable data:

  • Their contents can be changed without creating a new object.
  • Changes are reflected in all variables referencing this object.
  • It is important to consider this when passing such objects to functions to avoid unintended side effects.

Example:

my_list = [1, 2, 3]
my_list.append(4)  # the list has changed, a new element was added
print(my_list)  # [1, 2, 3, 4]