Python Functions

Funtion Declaration :   def Hello() :

print ("Hello")

Function Parameters : def Numbers(a,b):

if a > b ;

print a

else :

print b

print (2,3)

Funcation Local variables : def Func(x)

x = 21

print x

x = 29

function(x)

print x

Funtion Global Varuiables :

deffunc():
global x
print(x)
x = 12
print (x)
x = 21
print(x)
func()
print(x)

Function Default arguments :

def ad(a,b=4):
print(a*b)
ad('hello')
ad('chennai',2)

Function Keyword Arguments :

def func(a , b=5,c=10)

print 'a is', a,'and b is', b,'c is', c

func(3,7)

func(25, c=24)

func(c =50 , a= 100)

No comments:

Post a Comment