HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

Python Function


A function is a block of organised,reusable sets of instructions that is used to perform some related actions.


Uses of Function

Types of Function

User-defined Function

The function which is created by users is called user-defined function.

Example
def evenOdd( x ): 
    if (x % 2 == 0): 
        print("even")
    else: 
        print("odd")
   
    evenOdd(2) 
    evenOdd(3)  
    
    Output
    even
    odd
              

Built-in Function

There are various built-in function:


Name Description
abs() Returns the absolute value of a number.
all() Returns true if all items in an iterable objects are true.
any() Returns true if any items in an iterable objects are true.
ascii() Returns a readable version of an object.Replaces non-ascii character with escape character.
bin() Returns the binary version of a number.
bool() Returns the boolean value of the specified object.