list and global variable: why there is no "global a" in test(). | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 Antworten
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