Python Pass by Value Vs Reference Read Today

Python is programming language for data science projects. Here functions play top role. Since re-usable code you can put in one function, and you can call as many times as you need. In functions the below example gives you an idea on Pass by value and reference.

In functions, two concepts, you can read. Once is Pass by value and the other one is Pass by reference.

Value and reference both you need to understand as Value – Literal and Reference – Address.

Pass by value and pass by reference in Python

python functions

Pass by Value

The output shows, the same values as defined in inside of function are displayed. It is not modified.

#function definition
#This function updates the passed values

pass by value

Pass by reference

The output is modified. This is different from as defined in function. This is due to in-built append function.

# This program demonstrates the concept of call by reference
#function definition

pass by reference

Related Posts

Advertisements