-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEX9_python.py
More file actions
52 lines (43 loc) · 1.46 KB
/
EX9_python.py
File metadata and controls
52 lines (43 loc) · 1.46 KB
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
#P1
def f1():
# local variable
s = "I live in khorramabad";
print(s);
# Main
f1();
"""this above part is illustrating the local variable which means worked in their own block for instance
s is a local variable in f1 function and hasn't been detected in main method"""
#P2
def f2():
# local variable
s = "I live in khorramabad";
print("Inside Function:",s);
#Main
f2();
print(s);
"""by moving subsequently forward to the next part can depict the local variable that can not work globally, means
should you use the local variable , you couldn't use it in main method. this is why you declared in limit block like:
f2 function"""
#P3
def f3():
global s;
s = "I live in khorramabad";
print(s);
# Main: Global Scope
s = "I live in Iran";
f3();
print(s);
"""on the other hand, the third part can deliniation the global variable which means : if you want to declared
a global variable , you can use it in all of the body of your code, for instance : you can use global s in f3
function or in main method and you can not change your amount"""
#P4
# This function uses global variables s
def f4():
s = "I live in khorramabad";
print(s);
#Main
s = "I live in Iran";
f4();
print(s);
"""to sum up, this part can demonstrate the global variable , which means : if you want to comment the 47th line
,you can see the amount of s in f4 function, if no, you can see the two dispersed amount of s"""