Apr-12-2020, 02:24 PM
Before you can subscript a variable, the variable must already exist. So when you do c[0] = 5, it first will search the local scope for c, and not finding it, will search the global scope for c.
If you did
If you did
c = [1, 2, 3] print(id(c), c) def demo(): c = [1, 2, 3] c[0] = 5 demo() print(id(c), c)You will see that the global c is not changed as there is now a local version created.