Understanding Global and Local Variables, Lambda Functions, and Recursive Functions in Python
name1 = 'dfg'
return
def ChangeGlobalVari2():
name1 = 'dfg'
return
print(name1)
When executing ChangeGlobalVari1(), the output will be dfg.
When executing ChangeGlobalVari2(), the output will be ddd.
If a global variable is of mutable type like a list or dictionary, there's no need to declare it as global.
li = [66] # Mutable type; ...
Posted on Sun, 02 Aug 2026 16:22:51 +0000 by bb_xpress