References
In this lesson, you'll learn about the concept of references in Python.
We'll cover the following...
Simple values and complex objects
In a technical sense, every value in Python is an object. In practice, there is a distinction between simple values and more complex objects. Numbers and Booleans can be considered simple values.
Let’s say, we have two values: a
and b
. If the value in variable a
is simple, and you execute the assignment b = a
, the value is copied from a
into b
. You can subsequently change the value in either a
or b
without affecting the value in the other variable.
However, consider the following scenario:
Press + to interact
a = [1, 2, 3]b = ab[1] = 99print(a) # prints [1, 99, 3]
In this example, a
is a list, and lists are a kind of object. This list ...