global vs local variables

Solutions on MaxInterview for global vs local variables by the best coders in the world

showing results for - "global vs local variables"
Océane
02 Apr 2020
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  
Paola
16 Aug 2018
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
local variable vs globalwhat difference between global variables and local variablesglobal vs localdifference between local and global variablessql set local variablesql declare a local variableglobal vs local variabledifference between local and global variables 3flocal vs global variableglobal and local variabledifference between local and global variable in sql serverlocal vs global variables examplewhat is the difference between global and local variableglobal and local variable differenceglobal and local variable pythonwhat are global and local variablesjs local vs global variablecan something be both local and global varlocal and global variables in sqlvar is local or globalwhat are the difference between local and global variablelocal global variablesdifferent between local and global variablelocal vs global variabel javascriptwhich is more preferrdd global variable or local variableglobal and local variables in pythonjavascript global vs local variableslocal vs global variableslocal and globalsql local variabledifference between a global and a local variablelocal vs global variableshow to declare global variable in sql serverglobal vs local variables in javascriptwhat are global variables and local variablesdifference between global and local variablediscuss the difference between global variable and local variablelocal vs global variables example in jslocal and global variablesvariables can be both local or globaldifference between a global and local variablecan a variable be both local and global global variables vs local variable in functionsjavascript local vs global variableslocal variables vs global variableslocal variables and global variablesdifference between local and global variablelocal and global variable pythondefrence between local and global variablesvariable local sqldifference global variable localglobal vs local variables javascriptdefine local and global variablesdifferent from local variables and globallocal and global variablelocal and global variables exampleswhat is the difference between a global and local variablewhat is the difference between local variables and global variablesglobal variable vs local variableglobal and local variableslocal vs global variables in sqlset local variable sqlwhat is the difference between local and global variablesdistinguish between local and global variablespython global variablesql create local variabledifference local and global variablelocal variable vs global variableglobal vs local scope pythonlocal and global variables examoles what is the difference between local variable and global variablehow to use local variables in sql serverlocal or global variablesglobal variables vs local variablesdifference between global and local varia 3bbleglobal and local variables which is betterglobal vs local variablesdifference bw the local and global variablesdifference global variable local sqlglobal vs local variables