Functions in Python

Similar to other programming languages python also has:
  • user defined functions
  • built-in functions
Built-in functions are pre-defined in Python. For example id() which returns the id of the object and print() which prints the output are built-in functions.

user defined functions are the ones defined by python programmer. For example, if the programmer wants to perform sum of two variables, the program shall be as below

def sum(c,d):
    e = c+d
    print(e)

a = 10
b = 10
sum(a,b)

-------------------------------------------

The above program doesn't return any value. Let us assume a function has to return a value, then the return value from function shall be printed as below.

def sum(c,d):
    e = c+d
    return e

a = 10
b = 10
print(sum(a,b))

Post a Comment

0 Comments