showing results for - "local vs global variables"
Edoardo
01 May 2016
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  
Swan
21 Jan 2017
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.
queries leading to this page
variables can be both local or globaldifference between local and global variablelocal variables and global variablesvariable local sqlwhat are the difference between local and global variablewhat is the difference between local and global variableslocal and global variables examplesdefrence between local and global variablesdifference between a global and local variableglobal vs local variables javascriptsql declare a local variableglobal and local variable differencewhat are global variables and local variablesdifferent between local and global variableglobal and local variable pythondifference between local and global variable in sql serverlocal and global variableslocal and global variables in sqlvar is local or globallocal vs global variables in sqllocal vs global variablesdiscuss the difference between global variable and local variablewhat is the difference between global and local variableglobal vs local variablelocal and global variablelocal and global variables examoles difference global variable local sqllocal and globallocal variable vs global variablewhat is the difference between local variable and global variablepython global variableglobal variables vs local variable in functionsdefine local and global variableslocal vs global variables example in jsglobal vs local scope pythonhow to use local variables in sql serverglobal and local variabledifference local and global variablecan a variable be both local and global local vs global variables exampleglobal vs local variablessql set local variableglobal and local variables which is betterglobal and local variablesdifference between global and local variablejavascript local vs global variablesjs local vs global variabledifference bw the local and global variablesdistinguish between local and global variableslocal variable vs globalsql local variablesql create local variablewhat is the difference between local variables and global variablesglobal and local variables in pythondifferent from local variables and globallocal vs global variabel javascriptlocal global variablesjavascript global vs local variableswhat is the difference between a global and local variablelocal vs global variableslocal or global variablesdifference between local and global variableswhich is more preferrdd global variable or local variablelocal variables vs global variablesglobal vs local variables in javascriptwhat are global and local variablescan something be both local and global vardifference between local and global variables 3fdifference between a global and a local variablehow to declare global variable in sql serverglobal vs localdifference global variable localglobal variable vs local variablelocal vs global variabledifference between global and local varia 3bbleset local variable sqllocal and global variable pythonwhat difference between global variables and local variableslocal vs global variables