首页 > 代码库 > Global & Local Variable in Python
Global & Local Variable in Python
Following code explain how ‘global‘ works in the distinction of global variable and local variable.
1 var = ‘Global Variable‘ 2 print(var) 3 4 def func1(): 5 var = ‘Local Variable‘ 6 print(var) 7 8 def func2(): 9 print(var)10 11 def func3():12 global var13 print (var)14 var = ‘Global Variable Changed in Function‘15 16 func1()17 func2()18 func3()19 20 print(var)
Expected Result:
Global Variable
Local Variable
Global Variable
Global Variable
Global Variable Changed in Function
Global & Local Variable in Python
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。