-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS09L57_script00.py
More file actions
45 lines (27 loc) · 847 Bytes
/
Copy pathS09L57_script00.py
File metadata and controls
45 lines (27 loc) · 847 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Scope of variables
a = 100
# We define a function which add two numbers
def f1():
a = 200
print(a)
def f2():
print(a)
f1()
f2()
## So heere we can see how is it with the local scope and the global, it will be created a new local variable with the same name inside the function.
### but if we have for example
b = 100
def f3():
global b
b = 125 # global
# This will modify the global variable.
f3()
print(b)
### but we will happen if we have a list, that would be different we will able to modify elements inside a global list inside a function without using the global keyword
c = [1,2,3]
def f4():
# we can do the follwing and it will modify the global variable
c[0]= 99
print("Before running the function we had c = ",c)
f4()
print("After the function we have modify one element of c, c = ",c)