0

list and global variable: why there is no "global a" in test().

a = [10,20] def test(m): m.append(30) test(a) print(a) a is a global variable and it's changed by append in test(), but why there is no "global a" statement.

20th Jan 2019, 10:31 AM
sky
sky - avatar
2 Respostas
0
When you give an object like a list as argument in a function, it doesn't copy the object but modify it.
20th Jan 2019, 11:17 AM
Théophile
Théophile - avatar
0
That's hard to understand if you never learn c or c++ language.
20th Jan 2019, 11:18 AM
Théophile
Théophile - avatar