0
a = 5

def fun(b):
  global a
  a = 5
  print(a, b) # 5, 5 
  print (a is b) # True

def foo(b):
  global a
  a = 6
  print(a, b) # 6, 5 
  print (a is b) # False

fun(a)
foo(a)

So, I'm learning python and was playing around with identity/references. As per this link, identity of object never changes once it is created.

Why does the identity change when assigning a different value to variable a that is already created? Why assignment has different behavior in the two functions?

0 Answers0