meaning immutable and mutable 1

meaning immutable and mutable

A mutable object can be changed after it's created, and an immutable object can't.

Here is what the above code is Doing:
1. We create a variable called my_list and assign it the list [1, 2, 3].
2. We create a variable called my_tuple and assign it the tuple (1, 2, 3).
3. We try to update the first item in my_list to the value 2. This works.
4. We try to update the first item in my_tuple to the value 2. This causes an error.

Similar Posts