Pass by Reference

Understand the scope of pass by reference in detail.

We'll cover the following

This lesson will unfold a very tiny but tricky concept that can bring a cascading effect to our code if not handled with care.

Passing a parameter to a function

A function can change any mutable object passed as a parameter, but it can never replace it with another object. To understand it, let’s should jump straight to an example. Consider the following function:

def function(x, y):
    x += y
    return x

Now, let’s call this function in different ways and see the difference.

Create a free account to view this lesson.

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