Python Built-in Functions - A Complete Guide with Examples

Tutorial Playlist

Built in Functions in Python

Back in the Python Functions module, we learnt that there are three types of functions, namely, user-defined functions in Python, lambda functions in Python, and built in functions in Python. In this module, we will learn all that we need to know about built in functions in Python.

So, without further ado, let’s get started.

Python interpreter has various pre-defined functions that are readily available to use. We don’t have to define these functions to use them; we can directly call them. These functions are called built in functions.
In the previous modules of this Python tutorial, we have used various built in functions. The very basic built in function that we have used in almost every module is the print() function which is used to display a given object.

Get 100% Hike!

Master Most in Demand Skills Now!

Table of Built-in Functions in Python

The print() function is just one of many built in functions in Python. Let’s learn about more built in functions and their descriptions through the following table.

Python Function Description Example
abs() Returns the absolute value of a number. abs(-10) -> 10
all() Returns True when all elements in an iterable are True. all([True, True]) -> True
any() Checks if any element in an iterable is True. any([False, True]) -> True
ascii() Returns a printable representation of an object. ascii(‘ä’) -> ‘ä’
bin() Converts an integer to a binary string. bin(5) -> ‘0b101’
bool() Converts a value to Boolean. bool(1) -> True
bytearray() Returns an array of the given byte size. bytearray(5) -> bytearray(b’\x00\x00\x00\x00\x00′)
bytes() Returns an immutable bytes object. bytes(5) -> b’\x00\x00\x00\x00\x00′
callable() Check if the object is callable. callable(len) -> True
compile() Compiles source into a code object. compile(‘5 + 5’, ‘<string>’, ‘eval’)
complex() Creates a complex number. complex(1, 2) -> (1+2j)
delattr() Deletes an attribute from an object. delattr(obj, ‘attr’)
dict() Creates a Python dictionary. dict(a=1, b=2) -> {‘a’: 1, ‘b’: 2}
dir() Returns attributes of an object. dir([]) -> [‘append’, ‘clear’, …]
divmod() Returns a tuple of quotient and remainder. divmod(5, 2) -> (2, 1)
enumerate() Returns an enumerate object. enumerate([‘a’, ‘b’]) -> (0, ‘a’),(1, ‘b’)
eval() Executes a given string as Python code. eval(‘5 + 5’) -> 10
exec() Executes dynamically created Python code. exec(‘a = 5’)
filter() Constructs an iterator from true elements of an iterable. filter(lambda x: x > 0, [-1, 2]) -> [2]
float() Converts a value to a floating-point number. float(‘2.5’) -> 2.5
format() Formats a value into a string. {:.2f}’.format(3.14159) -> ‘3.14’
frozenset() Returns an immutable frozenset object. frozenset([1, 2]) -> frozenset({1, 2})
getattr() Gets the value of a named attribute. getattr(obj, ‘attr’)
globals() Returns the global symbol table as a dictionary. globals() -> {‘__name__’: ‘__main__’, …}
hasattr() Checks if an object has a named attribute. hasattr(obj, ‘attr’) -> True
hash() Returns the hash value of an object. hash(‘test’)
help() Invokes the interactive help system. help(abs)
hex() Converts an integer to hexadecimal. hex(255) -> ‘0xff’
id() Returns the identity of an object. id(obj)
input() Reads a line of input from the user. input(‘Enter: ‘)
int() Converts a value to an integer. int(’10’) -> 10
isinstance() Checks if an object is an instance of a class. isinstance(5, int) -> True
issubclass() Checks if a class is a subclass of another. issubclass(bool, int) -> True
iter() Returns an iterator for an object. iter([1, 2, 3])
len() Returns the length of an object. len([1, 2, 3]) -> 3
list() Creates a list. list((1, 2)) -> [1, 2]
locals() Returns the local symbol table as a dictionary. locals() -> {…}
map() Applies a function to an iterable. map(str, [1, 2]) -> [‘1’, ‘2’]
max() Returns the largest item in an iterable. max([1, 2, 3]) -> 3
memoryview() Returns a memory view object. memoryview(b’abc’)
min() Returns the smallest item in an iterable. min([1, 2, 3]) -> 1
next() Returns the next item from an iterator. next(iter([1, 2])) -> 1
object() Creates a featureless object. object()
oct() Converts an integer to octal. oct(8) -> ‘0o10’
open() Opens a file and returns a file object. open(‘file.txt’)
ord() Returns the Unicode code point for a character. ord(‘A’) -> 65
pow() Returns the power of a number. pow(2, 3) -> 8
print() Prints a value to the console. print(‘Hello’)
property() Returns a property object. @property
def name(self): return self._name
range() Creates a sequence of integers. range(5) -> 0, 1, 2, 3, 4
repr() Returns a string representation of an object. repr(‘test’) -> ”test”
reversed() Returns a reversed iterator. reversed([1, 2]) -> [2, 1]
round() Rounds a number to the nearest integer. round(2.5) -> 3
set() Creates a set. set([1, 2, 3])
setattr() Sets the value of an object’s attribute. setattr(obj, ‘attr’, 5)
slice() Creates a slice object. slice(0, 10)
sorted() Returns a sorted list from an iterable. sorted([3, 1]) -> [1, 3]
staticmethod() Creates a static method. @staticmethod
def method(): pass
str() Converts an object to a string. str(10) -> ’10’
sum() Adds items in an iterable. sum([1, 2]) -> 3
super() Returns a proxy for the parent class. super().method()
tuple() Creates a tuple. tuple([1, 2]) -> (1, 2)
type() Returns the type of an object. type(5) -> <class ‘int’>
vars() Returns the __dict__ attribute of an object. vars(obj)
zip() Returns an iterator of tuples. zip([1, 2], [‘a’, ‘b’]) -> [(1, ‘a’), (2, ‘b’)]
__import__() Dynamically imports a module. __import__(‘os’)

Unlock the Power of Data Science and AI
Shape Your Future in Data Analysis
quiz-icon

These are the built in functions in Python. They all perform their respective operations when executed. To use these Python built in functions, all we have to do is to call them and pass the relevant argument as mentioned in the description of each built in function.

With this, we come to the end of this module in Python Tutorial. Now, if you want to know, why Python is the most preferred language for data science, you can go through this blog on Python Data Science tutorial.

Further, check out our offers for Python training Courses and also refer to the trending Python interview questions and answers prepared by the industry experts.

Our Python Courses Duration and Fees

Program Name
Start Date
Fees
Cohort starts on 11th Jan 2025
₹20,007
Cohort starts on 11th Jan 2025
₹20,007
Cohort starts on 11th Jan 2025
₹20,007

About the Author

Technical Research Analyst - Full Stack Development

Kislay is a Technical Research Analyst and Full Stack Developer with expertise in crafting Mobile applications from inception to deployment. Proficient in Android development, IOS development, HTML, CSS, JavaScript, React, Angular, MySQL, and MongoDB, he’s committed to enhancing user experiences through intuitive websites and advanced mobile applications.