Aliases

Learn how aliasing works in Python and how it is used in functional programming.

We'll cover the following...

Aliasing

Aliasing is when two different variables reference the same object in Python. For example, consider this code:

Press + to interact
t = (10, 20, 30, 40, 50)
u = t
print(t[2]) # 30
print(u[2]) # 30

We assign a tuple value to variable t in line 1. This means that t holds a reference to the tuple object. The tuple itself is stored in memory somewhere.

When we set u = t in line 2, we are actually copying the reference into the variable, u. We don’t create a copy of the actual tuple itself. There is only one tuple, but both t and ...

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy