-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path49.scope2.py
More file actions
27 lines (21 loc) · 817 Bytes
/
49.scope2.py
File metadata and controls
27 lines (21 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 49. Scope In Python p2
"""
# If you operate with the same variable name inside and outside of a function, Python will treat
them as two separate variables, one available in the global scope (outside the function) and
one available in the local scope (inside the function).
# If you need to create a global variable, but are stuck in the local scope, you can use
the global keyword. The global keyword makes the variable global.
"""
x = 20
z = 5
def myFunc():
x = 10
global y
y = 30
z = 50
print("The value of x inside the function= "+str(x))
print("The value of z inside the function= "+str(z))
myFunc()
print("The value of x outside the function= "+str(x))
print("Access to the value of y outside the function = "+str(y))
print("The value of z outside the function= "+str(z))