20250507(expression in arg)

Run Settings
LanguagePython
Language Version
Run Command
# Prove Python will evaluate expression before passing to defined function. def b(): print("I am from function b") return 1 def a(i,j): x = i y = j z = x + y print(z) a(b()+b(), 3) #a(b()+b()+None, 3) #print(globals()) # With default values. def b(): print("I am from function b") return 1 def a(i,k,j=b()+4): x = i y = j z = x + y print(z) a(b()+b(), 1) # def b(): print("I am from function b") return 1 def c(): print("I am from function c") return 1 #from dio import * import dio as d d.e() def a(i,j=c()+4): #evaluate all function default value then caller expression x = i x = b() y = j z = x + y print(z) b()+b() print(globals()) # Next day after double checking from Teacher. Python really will calculate all expressions before stack any functions. # This design is handly for automation calculation. Javescripts won't behave like this. # However, this would led to following problem. def b(): #global i print(i) def a(x=1): b() print(x) i = 10 a() # No problem above, but shows problem below if you define function later. def c(x=1+d()): d() print(x) def d(): #global i print(i) i = 10 c() # Local variables vs global variables def a(x=1): b() print(x) def b(): i = 1 i = i + 1 i = 10 a() print(i)
def e(): print("I am from function e") return 1 def a(i,j=e()+4): #evaluate all function default value then caller expression z = i + j print(z)
Editor Settings
Theme
Key bindings
Full width
Lines