fork download
  1. def f1(i):
  2. print('f1 is called')
  3. print('Before assignment the ID of "i" is: {}'.format(id(i)))
  4. print('Notice that the ID is the same as initial ID.')
  5. i = i + 1
  6. print('After assignment the ID of "i" is: {}'.format(id(i)))
  7. print('''Not "i" inside the functions refers to the different address,
  8. so the changes to "i" won't be reflected outside the function.''')
  9.  
  10.  
  11. i = 1
  12. print('Initial ID of "i" is: {}'.format(id(i)))
  13. f1(i)
Success #stdin #stdout 0.02s 5852KB
stdin
Standard input is empty
stdout
Initial ID of "i" is: 3078065760
f1 is called
Before assignment the ID of "i" is: 3078065760
Notice that the ID is the same as initial ID.
After assignment the ID of "i" is: 3078065776
Not "i" inside the functions refers to the different address,
so the changes to "i" won't be reflected outside the function.