Function in Python
Code Example
Example 1:
def full_name():
print("My name is : Kuntal Samanta")
full_name()
output : My name is : Kuntal Samanta
Example 2:
def full_name(fn, ln):
print("My name is : ", fn, " ", ln)
full_name("Kuntal", "Samanta")
output : My name is : Kuntal Samanta
Example 3:
def full_name(fn="Firstname, ln="Lastname"):
print("My name is : ", fn, " ", ln)
full_name()
output : My name is : Firstname Lastname
full_name("Kuntal", "Samanta")
output : My name is : Kuntal Samanta
Example 4:
def add(x, y):
return x + y
result = add(10, 20)
print(result)
output: 30
Example 5:
def demo(x, y):
return x, y
r1, r2 = demo(10, 20)
print(r1, r2)
output: 10, 20
Comments
Post a Comment