Global variable & keyword

l=10 #Global variable
def function1(n):
m=8 #local variable
print(n, "this is printed")
global l#used to change global variable in local area
l=l+5
# l=5 #local variable
print(l,m)

function1("this is me")

print(l)

#print(m)

l=10#global variable
def function1(n):
#l=5#local var
global l
#this is global keyword which give permission to change the global var in local area
l=100
a=6#local var
print(l,a)
l=l+5
print(n,"Iwas born on 26 jan 2002")

function1("my name is N harish,")

print(l)

def harish(): #this is for more understanding
k=20
def shiva():
global k
k=5
print(k)
shiva()
print(k)

harish()

Comments

Popular posts from this blog

Steps taken by a compiler to execute a C program

Tokens in C

Variables and Data Types in C