PASS BY OBJECT REFERENCE IN PYTHON
def modify(name):
print("Original Name: ",name)
print("Original Address of name: ",id(name))
name="Umesh"
print("Modified Name: ", name)
print("Modified Name address: ", id(name))
title = "Leo"
print("Title: ", title)
print("Original Address of Title: ",id(title))
modify(title)
print("Name after update: ", title)
print("Memory address of title after update: ",id(title))
The output of this code is:
The same original address of Title and name shows that its not due to "Pass by Value". "Pass by Reference" also don't work in python. Infact python works with "Pass by Object Reference". When we passed value to the function then its object of the value will be passed to the function as argument. In the case of integer, string or value, when you try to update its value then a new variable will be created with a different memory address for the updated value since these data types are immutable( unmodifiable).
Leave PASS BY OBJECT REFERENCE IN PYTHON to:
Read more #hive-148441 posts
Best Posts From Leo Umesh
We have not curated any of leoumesh's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Leo Umesh
- The Tattoo of My Newborn Baby Girl Forever Inked on My Skin
- Long Weekend Food Feast With Wife
- String Manipulation in C#: Part 2
- String Manipulation in C#
- Introduction to C# and .NET
- Weekend Escape To Falls
- Evening Barbecue With Favourite Beer 🍺 🍻
- NumPy Broadcasting
- Summer BBQ
- Review of "The Day of The Jackal" Series
- Wonders of Wave Rock, Western Australia
- Trying To Make Authentic Chicken Dum Biryani At Home
- Beautiful Ocean Lookout in South West Australia
- Esperance: Hidden Paradise of Western Australia
- Cruising Through Blue Haven Beach
- My First Tattoo
- Exploring Flavoursome Veggie Indian Cuisines
- Australia's Popular Drink: Homemade
- An Everlasting Flowers
- Unexpected Rainbow At Wellington Dam, Western Australia