Python Local & Global Variables
Concept
Global variables are the ones that are defined and declared outside a function and we need to use them inside a function.
Code
Example 1:
def foo():
total = 1
return total
total = 0
print(foo())
>>> 1
Example 2:
def fun():
print(s)
s = "Hello World"
fun()
>>> Hello World
Comments
Post a Comment