You are on page 1of 4

In 

[ ]:
Functions

In [ ]:
Without Arguments Without Return Type

In [3]:
def add():
a = 5
b = 6
c = a + b
print(c)

add() # We dont pass arguments here

In [ ]:
With Arguments Without Return Type

In [5]:
def add(a,b):
c = a + b
print(c)

add(5,6)

11
In [ ]:
Without Arguments With Return Type

In [6]:
def add():
a = 5
b = 6
c = a + b
return c

x = add()
print(x)

11
In [ ]:
With Arguments With Return Type

In [7]:
def add(a,b):
c = a + b
return c

x = add(5,6)
print(x)

11
In [ ]:

In [ ]:
Other Important Info

In [ ]:
Passing Variable instead of value

In [ ]:
def add(a,b):
c = a + b
return c

a = 5
b = 6
x = add(a,b)
print(x)

In [ ]:
More about Return Type - Multiple Return Values

In [8]:
def add(a,b):
c = a + b
return a, b, c

a = 5
b = 6
a, b, x = add(a,b)
print(x)

11
In [14]:
def add(a,b):
c = a + b
return a, b, c

a = 5
b = 6
x = add(a,b)
print(x)

(5, 6, 11)
In [ ]:
Default Arguments

In [10]:
def add(a,b=10):
c = a + b
return c

a = 5
b = 6
x = add(a)
print(x)

15
In [11]:
def add(a,b=10):
c = a + b
return c

a = 5
b = 6
x = add(a,b)
print(x)

11
In [ ]:
Passing Datastructures

In [12]:
def add(a):
a.append(77)
return a

a = [3, 4, 5, 8 ,99, 'a']


x = add(a)
print(x)

[3, 4, 5, 8, 99, 'a', 77]


In [ ]:

In [ ]:
Exercise
4 Functions
use pi as default argument
--------------------
1. Area of a triangle
2. Volume of a sphere
3. celcius to fahrenheit

Pass List and do insert with value , position


Pass List and do delete with value , position
Pass Tuple and clear the tuple datastructure and return

You might also like