+ 1
Why is this possible?
#normally working def a(): return b() def b(): print("Hello") a() #NameError X = Y Y = 3 print(X) I think both are wrong because b() and Y are used before they're defined or assigned. But the former works normally and the latter doesn't. Why?
2 Antworten
+ 2
The functions work because of how code is compiled. I wont get into the details but all you need to know is that functions aren't compiled one after another. They are basically compiled at the same time which allows your first example to run. Code in functions is compiled one after another which is why X = Y Y = 3 won't work. Don't mix them up. Functions aren't your normal lines of code.
+ 1
Thank you very much!