How to Pass Arguments [Value and Reference] in Python Function

Python is a programming language for data science projects. Here functions play a 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.


Advertisements

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

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.