+ 4

Python variable scopes

I am just a Python challenger, but I also want to learn something and here is the question: c = 5 def b(x): c += x b(c) print (c) This will not work, now how to access c from within b() so it's value can be changed there? Thanks

16th Mar 2019, 3:27 AM
Dejan Dozet
Dejan Dozet - avatar
1 Respuesta
+ 7
c = 5 def b(x): global c c += x b(c) print(c)
16th Mar 2019, 3:32 AM
Diego
Diego - avatar