I need help to understand the below;
def increment(n):
n += 1
return n
a = 1
increment(a)
print(a)
The output is 1
and not 2
as per my little understanding of Python.
I have added the line return n
in an attempt to pass on the value from n
to a
. It still does not.
As per a comment from @TimRoberts
below, editing the above code with a = increment(a)
gives an output of 2
.
I am writing this here to highlight this one of many good comments below.