You are on page 1of 7

How to call function

def greet():
print("Hello")
greet()
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py==
Hello
>>>

#positional Argument (Single Argument passed)


#Calling the function
def greet(name):
print("Hello",name)
greet("Aman")
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
Hello Aman
>>>

#Default Argument
def greet(name="Raj"):
print("Hello",name)
greet()
greet("Aman")
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
Hello Raj
Hello Aman
>>>
#Multiple Argument
def greet(name,post):
print("Hello",name, "Good Morning")
print("your post is=",post)
greet("Aman" ,"manager")
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
Hello Aman Good Morning
your post is= manager
>>>

def greet(name,post):
print("Hello",name, "Good Morning")
print("your post is=",post)
greet("manager" ,"Aman")
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
Hello manager Good Morning
your post is= Aman
>>>

#Keywaord Argument
def greet(name,post):
print("Hello",name, "Good Morning")
print("your post is=",post)
greet(post="manager" ,name="Aman")
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
Hello Aman Good Morning
your post is= manager
>>>

#Variable length Argument


def greet(*name):
for i in name:
print("Hello",i, "Good Morning")

greet("Aman","Raj","Rakesh","Tom","Jerry")
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
Hello Aman Good Morning
Hello Raj Good Morning
Hello Rakesh Good Morning
Hello Tom Good Morning
Hello Jerry Good Morning
>>>

# Returning the functions


def simple_interest(p,r,t):
si=(p*r*t)/100
return si
print("Simple Interest is=",simple_interest(1000,5,3))

==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===


Simple Interest is= 150.0
>>>
Scope of a variables

Main Function
def simple_interest(p,r,t):
si=(p*r*t)/100
print(si)
def main():
print("I am in main function")
simple_interest(1000,5,3)
main()
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
I am in main function
150.0
>>>

Main Function
def simple_interest(p,r,t):
si=(p*r*t)/100
print(si)
def main():
print("I am in main function")
simple_interest(1000,5,3)
if __name__=='__main__':
main()
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
I am in main function
150.0
>>>

# Recursion : It is function calling itself again and again


# There are two parts : Teminating part and Recursive part

#Infinite Recursion function


def main():
infinite()
def infinite():
print("hello")
infinite()
if __name__=='__main__':
main()
>>>

==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===


>>>
hello
hello
hello
hello……………………..
# Terminating Recursion function
def main():
infinite(10)
def infinite(count):
if count==0:
return
print("hello", count)
count=count-1
infinite(count)
if __name__=='__main__':
main()
>>>
==== RESTART: C:/Users/schittora/OneDrive/Desktop/online class python/qwe.py ===
hello 10
hello 9
hello 8
hello 7
hello 6
hello 5
hello 4
hello 3
hello 2
hello 1
>>>

You might also like