Search your course

Functions


Functions are of two types, either they will return some results or they just do processing inside.

Lets define a simple function that take two arguments and return addition of those two variables.

 

 

def main(a,b):
    return a+b

result = main(2,3)
print("Result of 2 passed arguments is : ",result)

 

 

In the same way lets create simple python function that will return square of argument passed in function

 

def main(a):
    return a**2

print(main(3))

 

You can also pass as many arguments in function as you want, for that use *args as an argument and list of arguments will be created in args variable and you can iterate through it.

 

def main(*args):
    for i in args:
        print(i)


print(main(3,4,"Usman","Alex","Maria"))

and it will print out :

3

4

Usman

Alex

Maria

 

Subscribe to my youtube channel