forked from hariom20singh/python-learning-codes
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable_GlobalVariable.py
More file actions
Latest commit
41 lines (32 loc) · 752 Bytes
/
Copy pathVariable_GlobalVariable.py
File metadata and controls
41 lines (32 loc) · 752 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
x="awesome"#x is global variable
defmyfunction():
print("This is value of Global Variable : "+x)
print()
myfunction()
print()
g="awesome"#global variable
defmyfun():
g="fantastic"#Value of g is changed at local level
print("Python is "+g)
myfun()
print("Python is : "+g)#global value printed
print()
print()
#Global keyword
#To create a global variable inside a function, you can use the global keyword.
#Example
deffun1():
globalx
x="fantastic "
fun1()
print("Python is "+x )
print()
#Example
#To change the value of a global variable inside a function,
# refer to the variable by using the global keyword:
x="fantastic"
deffun1():
globalx
x="awesome "
fun1()
print("Python is "+x )