From 2e938a6bb8b2ce953004728dc5f1fadb85fba14a Mon Sep 17 00:00:00 2001 From: Junior Date: Tue, 25 Jun 2024 10:17:56 -0400 Subject: [PATCH] Added a bit about global variables --- Python/002_globals.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Python/002_globals.py diff --git a/Python/002_globals.py b/Python/002_globals.py new file mode 100644 index 0000000..09a0a37 --- /dev/null +++ b/Python/002_globals.py @@ -0,0 +1,34 @@ +# Global Scope + +# We will discuss scope in the context of functions and classes +# at a later point. + +# More detailed reading: https://realpython.com/python-constants/ + +# The "scope" of anything (variable, function, etc.) means +# "where is this thing available". + +# For this initial introduction we will only be discussing +# the "global scope". Global means "available everywhere". +# Anything defined in the global scope can be accessed in +# the main part of the program, inside the body/blocks of +# a function, and from within classes. + +# Any variable declared in the top part of the program is +# technically a global variable and can be accessed anywhere. +# However, it is (usually) considered bad form to change global +# variable values inside functions and classes. + +# We use a special notation to define global variables which +# are intended to hold values for settings and such. +# Create them using all capital letters. Visual Studio Code +# will actually color these slighly differently so it is obvious. + +MAX_LOOPS = 500 + +loop_count = 0 + +# Notice that these two variables are slightly different colors. +# Nothing prevents you from changing the value of an all upper +# case variable, but the convention of using all caps is meant +# to indicate that the value SHOULDN'T be changed. \ No newline at end of file