From c80e85237a0dcca7c73bcd975512019a43760acf Mon Sep 17 00:00:00 2001 From: Sindhuja Golagani Date: Fri, 27 Feb 2026 18:49:33 +0530 Subject: [PATCH] Document variable scope rules in P02_VariableScope.py Added comments explaining variable scope rules and the LEGB rule. --- Programs/P02_VariableScope.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Programs/P02_VariableScope.py b/Programs/P02_VariableScope.py index 6286822..ecf8610 100644 --- a/Programs/P02_VariableScope.py +++ b/Programs/P02_VariableScope.py @@ -14,3 +14,22 @@ def test(): if __name__ == '__main__': test() print(x) #prints 'Global x' + + +#Author: OMKAR PATHAK +#This programs shows the rules for variable scope + +# LEGB Rule: Local, Enclosing, Global, Built-in + +x = 'Global x' + +def test(): + #global x + y = 'Local y' + x = 'Local x' + print(x +', '+ y) #prints 'Local x' and 'Local y' + +if __name__ == '__main__': + test() + print(x) #prints 'Global x' +