PASS BY OBJECT REFERENCE FOR MUTABLE DATA TYPES
In the last type we see Pass by Object Reference for immutable data type in python and in this we would do the same for mutable data types which are usually dictionary, list, tuple or set. Whenever you try to update these data types, a new object of these data types are not created in the memory and the value gets updated in the same memory address. This is because these data types are modifiable. Here's thee program demonstrating this concept.
def update(list):
print("List before updating any value: ",list)
print("Memory address of list before updating any value: ",id(list))
list.append("Cuba")
print("List after updating the value: ",list)
print("Memory address of list after updating the value: ",id(list))
list=["Brazil","Finland","Maldives","Rwanda"]
print("List before calling the function: ",list)
print("Memory address of list before the calling function: ", id(list))
update(list)
print("List after calling the function: ",list)
print("Memory address of list after calling the function: ", id(list))
You can see the output as:
Leave PASS BY OBJECT REFERENCE FOR MUTABLE DATA TYPES to:
Read more #python 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