Page Body

Pass-By-Value, Reference, and Assignment

Rodrigo Girão Serrão, Mathsapp:

When you call a function in Python and give it some arguments... Are they passed by value? No! By reference? No! They're passed by assignment.

Many traditional programming languages employ either one of two models when passing arguments to functions:

  • some languages use the pass-by-value model; and
  • most of the others use the pass-by-reference model.

Having said that, it is important to know the model that Python uses, because that influences the way your code behaves.

In this Pydon't, you will:

  • see that Python doesn't use the pass-by-value nor the pass-by-reference models;
  • understand that Python uses a pass-by-assignment model;
  • learn about the built-in function id;
  • create a better understanding for the Python object model;
  • realise that every object has 3> very important properties that define it;
  • understand the difference between mutable and immutable objects;
  • learn the difference between shallow and deep copies; and
  • learn how to use the module copy to do both types of object copies.

Enjoyed this post?

Subscribe to the feed for the latest updates.