Why does python behave this way with variables?
问题 I have been trying to understand why python behaves this way, in the block of code below. I have done my research but couldn't find a good answer so I came here to see if anyone can point me in the right direction or provide a good clarification. I understand that it has to do with some old ALGOL principle, but I don't fully understand it. var = 5 def func1(): print(var) func1() def func2(): var = 8 print(var) func2() def func3(): print(var) var = 8 func3() The output of this code is as