Problem Statement
Explain how arguments are passed in Python. Is it by value or by reference?
Explanation
Python follows a model known as pass by object reference. This means the reference to the object is passed to the function, not the actual value or a copy.
If the object is mutable, like a list or dictionary, changes made inside the function affect the original object. For immutable objects such as integers or strings, a new object is created instead, giving the impression of pass by value.
Understanding this helps prevent bugs when modifying arguments within functions and explains why behavior differs between lists and numbers.
Code Solution
SolutionRead Only
def f(x): x.append(1) a=[0]; f(a); print(a)
