temp = 5 # global variable def passfun(x: int)-> int: print("temp in passfun = %d" % temp) return x + temp def main(): global temp temp = 10 temp = passfun(temp) print("temp in main = %d" % temp) if __name__ == "__main__": main() |
temp = 5 # global variable def passfun(x: int)-> int: print("temp in passfun = %d" % temp) return x + temp def main(): temp = 10 # local variable temp = passfun(temp) print("temp in main = %d" % temp) if __name__ == "__main__": main() |
Output:temp in passfun = 10
temp in main = 20
|
Output:temp in passfun = 5
temp in main = 15
|
Does the Python apply static scoping rule or dynamic scoping rule?
Who is parent of passfun?