Python Built-In Functions with Syntax and Examples

Functions provide efficiency and structure to a programming language. Python has many useful built-in functions to make programming easier, faster, and more powerful.

Here is a list of Phyton’s built-in functions:

abs() all() any() ascii()
bytearray() bytes() bin() bool()
callable() chr() classmethod() compile()
complex() delattr() dict() dir()
divmod() enumerate() eval() exec()
filter() float() format() frozenset()
getattr() globals() hasattr() hash()
help() hex() id() __import__()
input() int() isinstance() issubclass()
iter() len() list() locals()
map() max() memoryview() min()
next() object() oct() open()
ord() pow() print() property()
range() repr() reversed() round()
set() setattr() slice() sorted()
staticmethod() str() sum() super()
tuple() type() vars() zip()

The input() Function

Programs usually require input that can come from different sources: keyboard, mouse clicks, database, another computer’s storage, or the internet. Since the keyboard is the most common way to gather input, Python provided its users the input() function. This function has an optional parameter called the prompt string.

The range() function

Python has a more efficient way to handle a series of numbers and arithmetic progressions and this is by using one its built-in functions: range(). The range function is particularly useful in ‘for loops’.

Example

>>> range(5)
 range(0, 5)
>>>list(range(5)) 
[0, 1, 2, 3, 4] 

abs()

The abs() function returns the absolute value of a single number. It takes an integer or float number as argument and always returns a positive value.

Example

>>> abs(-10) 
10 
>>> abs(5)
 10

max()

The max() function takes two or more arguments and returns the largest one.

Example

>>> max(9, 12, 6, 15)
 15

min()

The min() function takes two or more arguments and returns the smallest item.

Example

>>> min(23, -109, 5, 2)
 -109

type()

The type() function returns the data type of the given argument.

Example

>>> type(12) 
    <class 'int'>
>>> type(12.5) 
   <class 'float'> 

len()

The len() function returns the length of an object or the number of items in a list given as argument.

Example

>>> len(“Cseworldonline”)
 14