Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Object Passing in Python

In this lesson, you’ll learn that Python doesn’t pass objects by value or reference. Python passes objects by assignment instead. In the examples, you’ll see how this differs when the object is mutable or immutable.

Comments & Discussion

carl on July 15, 2020

At ~4:23 in Object Passing in Python you inadvertently described the list type as immutable. It’s fairly clear from the context that you meant to say mutable, but might be worth an edit .

carl on July 15, 2020

When describing pass-by-assignment, it would have been very helpful to show what that means in much the same way as you showed how assigning names to objects works.

Given this function definition and call:

def foo(v):
  v += 1

w = 1
foo(w)
print(w)

The pass-by-assignment behavior makes this roughly equivalent to

w = 1
v = w     # pass by assignment -- now v is just another name for w
v += 1    # now v is replaced by a new object containing 2
del(v)    # after we return from v, the name v no longer exists
print(w)  # w still points at the same object containing 1

Become a Member to join the conversation.