-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path63_Python_Scope.py
72 lines (51 loc) · 896 Bytes
/
63_Python_Scope.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Python Scope
print("Python Scope:\n")
# Local Scope
print("Local Scope")
print("Example 1")
def myfunction():
x = 100 # local variable
print(x)
myfunction()
# print(x) # error
print("\nFunction inside function scope:")
print("Example 2")
def myfunction2():
y = 25
def myinnerfunction():
print(y)
myinnerfunction()
myfunction2()
print("\nGlobal Scope")
print("Example 3")
z = 1 # global variable
def myfunction3():
print(z)
myfunction3()
print(z)
# Naming Variables
print("\nNaming Variables")
print("Example 4")
m = 25
def myfunction4():
m = 5
print(m)
myfunction4()
print(m)
# Global Keyword
print("\nGlobal Keyword")
print("Example 5")
def myfunction5():
global n
n = 10
print(n)
myfunction5()
print(n)
# Changing a global var value inside a scope
print("\nExample 6")
o = 400
def myfunction6():
global o
o = 500
print(o)
myfunction6()