-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocal_Global_Variables.py
61 lines (45 loc) · 1.08 KB
/
Local_Global_Variables.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
Local and Global variables: Local variables are variables used in given function. Other functions
cant use that variable. But Global functions can be used by any function.
#Example for Local Variable:
def func1():
n = 5
print('n value is', n)
def func2():
n = 10
print('n value is', n)
func1()
#main
func2()
Output would be
============ RESTART: C:\Users\vinayb\Desktop\DESKTOP\Practice.py ============
n value is 10
n value is 5
>>>
#Example for Global Variable:
n = 10
def func1():
print('n value is', n)
def func2():
print('n value is', n)
func1()
#main
func2()
============ RESTART: C:\Users\vinayb\Desktop\DESKTOP\Practice.py ============
n value is 10
n value is 10
>>>
n = 10
def func1():
print('n value is', n)
def func2():
n = 35
print('n value is', n)
func1()
#main
func2()
============ RESTART: C:\Users\vinayb\Desktop\DESKTOP\Practice.py ============
n value is 35
n value is 10
>>>
You will get it better during the explanation. Explanation would become very lengthy which
is not useful & required.