Skip to main content

Posts

Showing posts from July, 2024

Pass by reference vs value in Python

  number before= 6  in function value updated to 12  after function num value= 6  list before ['E']  in function list updated to ['E', 'D']  after function list is  ['E', 'D'] In the above code, we have shown how Python uses call by reference object concept in its program. We pass an integer in function call_by_value() .  Integers are immutable objects hence Python works according to call by value, and the changes made in the function are not reflected outside the function.  We then pass list to function by reference. In function call_by_reference() we pass a list that is an mutable object. Python works according to call by reference in this function and the changes made inside the function can also be seen outside the function.