Look in call-by-value way the value of the argument is copied to the function and any changes made to the value inside the function will not affect the original argument.
In other words.. the argument is treated as a copy of the original value.
For example look in the following code:
def add(x):
x += 1
return x
a = 5
print(add(a)) # Output: 6
print(a) # Output: 5
_____________________
AND in call-by-reference way the memory address of the argument is passed to the function and any changes made to the value inside the function will affect the original argument.
In other words.. the argument is treated as a reference to the original value.
example:
def change(lst):
lst[0] = 'new value'
lst = ['old value']
change(lst)
print(lst) #Output: ['new value']
NOTE: in the above example the change() function takes a list as an argument and changes the first element of the list to 'new value'. This change is then reflected in the original list lst.
Answers & Comments
Verified answer
Look in call-by-value way the value of the argument is copied to the function and any changes made to the value inside the function will not affect the original argument.
In other words.. the argument is treated as a copy of the original value.
For example look in the following code:
def add(x):
x += 1
return x
a = 5
print(add(a)) # Output: 6
print(a) # Output: 5
_____________________
AND in call-by-reference way the memory address of the argument is passed to the function and any changes made to the value inside the function will affect the original argument.
In other words.. the argument is treated as a reference to the original value.
example:
def change(lst):
lst[0] = 'new value'
lst = ['old value']
change(lst)
print(lst) #Output: ['new value']
NOTE: in the above example the change() function takes a list as an argument and changes the first element of the list to 'new value'. This change is then reflected in the original list lst.