Sobes.tech
Junior — Middle

Millised muudetavad andmestruktuurid on Python keeles saadaval?

sobes.tech AI

Vastus AI-lt

In Python, there are several mutable data structures that can be modified after creation:

  • list — an ordered, mutable collection of elements. You can add, remove, and modify elements.
  • dict — a dictionary that stores key-value pairs. It allows modifying, adding, and removing pairs.
  • set — a collection of unique elements, mutable, supports addition and removal operations.
  • bytearray — a mutable sequence of bytes.

Example of using mutable structures:

my_list = [1, 2, 3]
my_list.append(4)  # Add element

my_dict = {'a': 1, 'b': 2}
my_dict['c'] = 3    # Add pair

my_set = {1, 2, 3}
my_set.add(4)       # Add element

my_bytes = bytearray(b'abc')
my_bytes[0] = 100   # Change first byte

These structures are widely used for storing and processing data when it is necessary to modify the content.