Member-only story
7 Useful Python Built-In Functions
Utilize these functions to write better Python code
Python has a variety of practical built-in functions and types available by default. In this article, I will explain seven of them and provide some simple and beginner-friendly examples.
I hope you enjoy it!
1. isinstance()
You can use the isinstance()
function to check if an object is an instance of some class. This is super useful when performing object-type comparisons. For instance:
Notice how the class info is a tuple in the last line ((list, float, int, bool)
) and the return value is True
. This is because the isinstance()
function checks if any of the objects is an instance of any of them.
2. map()
The map()
function is a replacement for a for
loop. It applies a function for each element of a list, for example. The map()
function returns a map object. This can easily be converted back to a list with the list()
function.