|
| 1 | +''' |
| 2 | +In python, everything is an object. |
| 3 | +Hence when we pass a list to a function and when we modify the list, |
| 4 | +the changes are reflected outside the function as well. |
| 5 | +For example, we can see that there is only one object and value and data are references to that object. |
| 6 | +''' |
| 7 | + |
| 8 | +def change_function(data): |
| 9 | + print ("Id of list received in method", id(data)) |
| 10 | + data[1] = 500 |
| 11 | + print ("Id of list after element modification in method", id(data)) |
| 12 | + |
| 13 | +value = [100, 200, 300] |
| 14 | +print ("List and its id before method call", value, id(value)) |
| 15 | +change_function(value) |
| 16 | +print ("List and its id after method call ", value, id(value)) |
0 commit comments