---
title: "Pass by Value and Pass by Reference in Python"
description: "Here's an example of how to work with pass-by-value and pass-by-reference in Python."
url: https://srinimf.com/2022/05/23/python-pass-by-value-vs-pass-by-reference-simple-example/
date: 2022-05-23
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2022/05/pexels-photo-7868979.jpeg?fit=1880%2C1255&ssl=1
categories: ["Python"]
tags: ["Pass by value and reference in Python"]
type: post
lang: en
---

# Pass by Value and Pass by Reference in Python

Passing a value and passing a reference explained below. Below is the simple example which shows [how to](https://srinimf.com/2023/06/11/the-real-use-of-unnest-function-in-db2-sql/) use these in python.

Related[How a MetaClass Works in Python and Real Usage](https://srinimf.com/2021/02/07/metaclasess-python2-vs-python3/)

![python pass value reference](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/06/python-pass-value-reference.png?resize=600%2C424&ssl=1)*Python Pass by Value Vs. Pass by Reference Simple Example*

## **What is Pass by value**

What is pass by value? Passing a value as an argument to the function. The pass-by-value concept explained in three steps.

- Create a function
- pass ***value*** as an argument to the function
- to verify the result

A literal (20) as an argument supplied here. So it is called pass-by-value.

```
def my_pass_by_value(b):
    b += 2
    print(b)
c=my_pass_by_value(20)
print(c)
The result:
22
None
** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

**Also read:** **Impress your audience with Microsoft PowerPoint**

## **What is Pass by reference**

Supplying a reference instead of value is called pass-by-refefence. The working principle you can see in the below example.

- Create a function
- pass ***reference*** as an argument to the function
- to verify the result

The below example tells how pass-by-reference works. Value not supplied, instead of the value provided a variable (reference).

```
def my_pass_by_reference(r):
    r += 10
    print(r)
ref1=100
h=my_pass_by_reference(ref1)
print(h)
The result
110
None
** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

Recent topics

- ## [30 SQL Practice Queries with Solutions — Run Them Live](https://srinimf.com/2026/10/01/30-sql-practice-queries-with-solutions-run-them-live/) [![30 SQL Practice Queries with Solutions — Run Them Live](https://i0.wp.com/srinimf.com/wp-content/uploads/2026/10/pexels-photo-5530473.jpeg?resize=867%2C1300&ssl=1)](https://srinimf.com/2026/10/01/30-sql-practice-queries-with-solutions-run-them-live/) Practice 30 SQL queries with solutions, from SELECT and JOINs to subqueries and window functions. Run SQL queries live in an interactive SQL Playground. --- October 1, 2026
- ## [Supercharge Your Database Skills: Try Our New Interactive SQL Plugin!](https://srinimf.com/2026/09/30/supercharge-your-database-skills-try-our-new-interactive-sql-plugin/) [![Supercharge Your Database Skills: Try Our New Interactive SQL Plugin!](https://i0.wp.com/srinimf.com/wp-content/uploads/2026/09/pexels-photo-1181469.jpeg?resize=1880%2C1255&ssl=1)](https://srinimf.com/2026/09/30/supercharge-your-database-skills-try-our-new-interactive-sql-plugin/) Struggling with database queries? Explore our new interactive SQL plugin to write, test, and master SQL directly in your browser. Try the live demo now! --- September 30, 2026
- ## [How to Count Spark Stages by Sight and Optimize Shuffles](https://srinimf.com/2026/09/27/how-to-count-spark-stages-by-sight-and-optimize-shuffles/) [![How to Count Spark Stages by Sight and Optimize Shuffles](https://i0.wp.com/srinimf.com/wp-content/uploads/2026/09/pexels-photo-14314638.jpeg?resize=1880%2C1253&ssl=1)](https://srinimf.com/2026/09/27/how-to-count-spark-stages-by-sight-and-optimize-shuffles/) Want to predict execution stages before running a job? Learn how to count Spark stages by sight with code breakdowns, shuffle rules, and optimization traps. --- September 27, 2026

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2022%2F05%2F23%2Fpython-pass-by-value-vs-pass-by-reference-simple-example%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2022%2F05%2Fpexels-photo-7868979.jpeg%3Ffit%3D1200%252C801%26ssl%3D1&description=Pass%20by%20Value%20and%20Pass%20by%20Reference%20in%20Python)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2022/05/23/python-pass-by-value-vs-pass-by-reference-simple-example/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2022/05/23/python-pass-by-value-vs-pass-by-reference-simple-example/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2022/05/23/python-pass-by-value-vs-pass-by-reference-simple-example/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2022/05/23/python-pass-by-value-vs-pass-by-reference-simple-example/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Pass%20by%20Value%20and%20Pass%20by%20Reference%20in%20Python&body=https%3A%2F%2Fsrinimf.com%2F2022%2F05%2F23%2Fpython-pass-by-value-vs-pass-by-reference-simple-example%2F&share=email)
-

### Like this:

Like Loading…
