Python Functions
A function can be defined as the organized block of reusable code which can be called
whenever required.
Python provide us various inbuilt functions like range() or print(). Although, the user can
create its functions which can be called user-defined functions.
Advantage of Functions in Python
There are the following advantages of Python functions.
o By using functions, we can avoid rewriting same logic/code again and again in a
program.
o We can call python functions any number of times in a program and from any place
in a program.
o We can track a large python program easily when it is divided into multiple functions.
o Reusability is the main achievement of python functions.
o However, Function calling is always overhead in a python program.
Python Built-in Functions
The Python built-in functions are defined as the functions whose functionality is
pre-defined in Python. The python interpreter has several functions that are always
present for use. These functions are known as Built-in Functions. There are several
built-in functions in Python which are listed below:
Python abs() Function
The python abs() function is used to return the absolute value of a number. It takes only one
argument, a number whose absolute value is to be returned. The argument can be an integer
and floating-point number. If the argument is a complex number, then, abs() returns its
magnitude.
Python all() Function
The python all() function accepts an iterable object (such as list, dictionary, etc.). It returns true
if all items in passed iterable are true. Otherwise, it returns False. If the iterable object is empty,
the all() function returns True.
Python all() Function Example
Python bool()
The python bool() converts a value to boolean(True or False) using the standard truth testing
procedure.
Python bool() Example
Python sum() Function
As the name says, python sum() function is used to get the sum of numbers of an iterable, i.e.,
list.
Python sum() Function Example
Python format() Function
The python format() function returns a formatted representation of the given value.
Python format() Function Example