Academy Data Science Neovarsity
Sign in
outside of the Function.
Example:
x = 5
def f1():
print("x in =", x)
f1()
print("x out=", x)
Output:
x in =5
x out=5
Live Events
Local Variables
Spark for Dat…
A variable declared inside the Function’s body is called a local variable. Such a Amit Singh
variable is said to have a local scope, i.e., it is only accessible within the Function 2
and not outside. 1778 January 3.00
2023 | Hrs
Example: 8:00 PM
Register with 1-
def f2():
Click
y = 3
View All Events
f2()
print(y)
Output:
NameError: name 'y' is not defined
Example: Global and Local Variables with the Same Name
x = 15
def f4():
x = 200
print("Local x:", x)
f4()
print("Global x:", x)