1# in functions we use Global vs Local variables
2# Global means as the name suggests it's Global (accessed anywhere in file)
3
4def player_health():
5 # Local variable
6 # Local variables can't be accessed outside of a function
7 player_health = 78
8
9# error
10print(player_health)
11
12
13# Global Variables
14player_strength = 2
15def increase_strength():
16 player_strength = 3 # this will give you an error because the player_strength
17 # is defined in the global scope so you can't modify it in a function
18
19 # if you try to print the global variable in function you can do it
20 print(player_strength)
21
22# Local
23 # only accessed/edited by the functions only
24# Global
25 # accessed/edited in global level not in functions
26 # only accessed by functions but not editable
27
28# if you got something by this example please upvote it
29
30
1Local variables:
2These variables can be used or exist
3only inside the function. These variables
4are not used or referred by any other function.
5
6Global variables:
7These variables are the variables which
8can be accessed throughout the program.
9Global variables cannot be created
10whenever that function is called.