Sobes.tech
Junior — Middle

Can you name mutable data structures used in programming?

sobes.tech AI

Answer from AI

In programming, mutable data structures are those whose contents can be changed after creation. In Python, they include:

  • Lists (list) — elements can be added, removed, or modified.
  • Dictionaries (dict) — key-value pairs can be changed, added, or removed.
  • Sets (set) — collections of unique elements that can be modified.
  • Bytearrays (bytearray) — a mutable sequence of bytes.

Example:

my_list = [1, 2, 3]
my_list.append(4)  # list has changed

my_dict = {'a': 1}
my_dict['b'] = 2    # dictionary has changed

my_set = {1, 2}
my_set.add(3)       # set has changed

Unlike them, immutable structures include strings, tuples, and numbers.