0

If you pass a list to a function ,then it behaved differently for above operation. I am confused if its call by value or call by reference?

def function1(list1)
    list1=[1,4,7,9]
    list1.append(80)

list2=[90,67,87,34]
function(list1)
print list1

list1.append() is appending to the list in list1 but in assignment, List in caller is unchanged.

Maroun
  • 94,125
  • 30
  • 188
  • 241
  • https://nedbatchelder.com/text/names.html – user2357112 May 22 '17 at 06:13
  • The python docs avoid both terms because they are used interchangeably across communities. Think of Python as call by assignment. The formal parameter names are assigned to the actual values when calling, nothing less, nothing more. – timgeb May 22 '17 at 06:16
  • 1
    Your sample code is currently nonsense (you can't pass `list1` to `function1`, that list doesn't exist. Also, you're missing a colon) – donkopotamus May 22 '17 at 06:16

0 Answers0