Download to read offline


![As you saw earlier, lists are mutable. Here’s another
example using the append() method:
a = list(('apple', 'banana', 'clementine'))
print(id(a))
a.append('dates')
print(id(a))
[Out:]
140372445629448
140372445629448
List](https://image.slidesharecdn.com/mutabledatatypesinpython-210622123534/75/Mutable-data-types-in-python-3-2048.jpg)
![Byte arrays represent the mutable version of bytes
objects. They expose most of the usual methods of
mutable sequences as well as most of the methods of the
bytes type. Items are integers in the range [0, 256).
b = bytearray(b'python')
print(id(b))
b.replace(b'p', b'P')
print(id(b))
[Out:]
139963525979808
139963525979808
Byte Arrays](https://image.slidesharecdn.com/mutabledatatypesinpython-210622123534/75/Mutable-data-types-in-python-4-2048.jpg)
![Sets
Python provides two set types, set and frozenset. They are
unordered collections of immutable objects.
c = set((‘San Francisco’, ‘Sydney’, ‘Sapporo’))
print(id(c))
c.pop()
print(id(c))
[Out:]
140494031990344
140494031990344
As you can see, sets are indeed mutable. Later, in the
Immutable Data Types section, we will see that frozensets
are immutable.](https://image.slidesharecdn.com/mutabledatatypesinpython-210622123534/75/Mutable-data-types-in-python-5-2048.jpg)



The document discusses mutable data types in Python, including lists, byte arrays, sets, and dictionaries, emphasizing their ability to be altered after creation. It illustrates examples of mutable lists and byte arrays, along with the properties of sets and dictionaries. The document also hints at a forthcoming section on immutable data types in Python.


![As you saw earlier, lists are mutable. Here’s another
example using the append() method:
a = list(('apple', 'banana', 'clementine'))
print(id(a))
a.append('dates')
print(id(a))
[Out:]
140372445629448
140372445629448
List](https://image.slidesharecdn.com/mutabledatatypesinpython-210622123534/75/Mutable-data-types-in-python-3-2048.jpg)
![Byte arrays represent the mutable version of bytes
objects. They expose most of the usual methods of
mutable sequences as well as most of the methods of the
bytes type. Items are integers in the range [0, 256).
b = bytearray(b'python')
print(id(b))
b.replace(b'p', b'P')
print(id(b))
[Out:]
139963525979808
139963525979808
Byte Arrays](https://image.slidesharecdn.com/mutabledatatypesinpython-210622123534/75/Mutable-data-types-in-python-4-2048.jpg)
![Sets
Python provides two set types, set and frozenset. They are
unordered collections of immutable objects.
c = set((‘San Francisco’, ‘Sydney’, ‘Sapporo’))
print(id(c))
c.pop()
print(id(c))
[Out:]
140494031990344
140494031990344
As you can see, sets are indeed mutable. Later, in the
Immutable Data Types section, we will see that frozensets
are immutable.](https://image.slidesharecdn.com/mutabledatatypesinpython-210622123534/75/Mutable-data-types-in-python-5-2048.jpg)

