what is the difference between local variable and global variable code example
Example 1: global vs local variables
def player_health():
player_health = 78
print(player_health)
player_strength = 2
def increase_strength():
player_strength = 3
print(player_strength)
Example 2: what is a global variable
Global variables allow you to access data between collections,
requests, test scripts, and environments. Global variables
are available throughout a workspace. I use Global variables
to quickly test something.
Example 3: local vs global variables
Local variables:
These variables can be used or exist
only inside the function. These variables
are not used or referred by any other function.
Global variables:
These variables are the variables which
can be accessed throughout the program.
Global variables cannot be created
whenever that function is called.