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

Unlock This Lesson

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

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences 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.

Pass by Reference in Python: Best Practices (Summary)

Python works differently from languages that support passing arguments by reference or by value. Function arguments become local variables assigned to each value that was passed to the function. But this doesn’t prevent you from achieving the same results you’d expect when passing arguments by reference in other languages.

In this course, you learned:

  • How Python handles assigning values to variables
  • How function arguments are passed by assignment in Python
  • Why returning values is a best practice for replicating pass by reference
  • How to use attributes, dictionaries, and lists as alternative best practices

For more information on concepts covered in this lesson, you can check out:


Sample Code (.zip)

14.3 KB

Course Slides (.pdf)

1.9 MB

mckown on Nov. 9, 2021

Just when I thought Halloween was over. Wait! What?

How many of us were swayed to try Python because of its simple syntax, easy-to-use REPL, and seductive lists vs limited arrays? Like high schoolers wandering into that empty, dark house.

I should have hesitated when I learned that there are no private variables. Nothing is private in Python. I should have run when I found that variables can be assigned any type willy-nilly. Strong data types are non-existent in Python. But I stayed. And, now, despite all the years of learning pass by reference and pass by value–common concepts that every American child learns by heart, the demons arise to sweep all that away to pass by assignment. It makes one’s hackles rise.

There are too many plots and subplots in this course. Can you make it through without having your programmer’s blood sucked out with every “AHA” moment. This course is good. SCARY good.

I’m looking forward to Howard Francis’ (and team!) next spooktacular installment.... If I ever recover my soul.

Become a Member to join the conversation.