Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python scope

# Variables have different levels of scope. Some include global and local scopes.

myVar = 5 # This is a global variable. It is not in any functions.

def myFunc():
  # global myVar
  
  myVar = 10 # This is a local variable

myFunc() # Runs myFunc
print(myVar) # Prints 5. The local variable in myFunc did not change the value of myVar.
# If you added 'global myVar' in myFunc, myVar would be changed to 10.
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Python #scope
ADD COMMENT
Topic
Name
1+3 =