Python built-in functions to know (2019)

downbad_1 pts0 comments

Built-in Functions in Python - Python Morsels

Built-in Functions in Python

Python's built-in functions list includes 71 functions now! Which built-in functions are worth knowing about? And which functions should you learn later?

Trey Hunner

March 9, 2022

27 min read

Python 3.10—3.14

Cheat Sheets

Overlooked Fundamentals

In every Intro to Python class I teach, there's always at least one "how can we be expected to know all this" question.

It's usually along the lines of either:

Python has so many functions in it, what's the best way to remember all these?

What's the best way to learn the functions we'll need day-to-day like enumerate and range?

How do you know about all the ways to solve problems in Python? Do you memorize them?

There are dozens of built-in functions and classes, hundreds of tools bundled in Python's standard library, and thousands of third-party libraries on PyPI.<br>There's no way anyone could ever memorize all of these things.

I recommend triaging your knowledge:

Things I should memorize such that I know them well

Things I should know about so I can look them up more effectively later

Things I shouldn't bother with at all until/unless I need them one day

We're going to look through the Built-in Functions page in the Python documentation with this approach in mind.

This will be a very long article, so I've linked to 5 sub-sections and 25 specific built-in functions in the next section so you can jump ahead if you're pressed for time or looking for one built-in in particular.

Which built-ins should you know about?

I estimate most Python developers will only ever need about 30 built-in functions , but which 30 depends on what you're actually doing with Python.

We're going to take a look at all 71 of Python's built-in functions, in a bird's eye view sort of way.

I'll attempt to categorize these built-ins into five categories:

Commonly known built-ins : most newer Pythonistas get exposure to these built-ins pretty quickly out of necessity

Overlooked by new Pythonistas : these functions are useful to know about, but they're easy to overlook when you're newer to Python

Learn these later : these built-ins are generally useful to know about, but you'll find them when/if you need them

Maybe learn these eventually : these can come in handy, but only in specific circumstances

You likely don't need these : you're unlikely to need these unless you're doing something fairly specialized

The built-in functions in categories 1 and 2 are the essential built-ins that nearly all Python programmers should eventually learn about.<br>The built-ins in categories 3 and 4 are the specialized built-ins , which are often very useful but your need for them will vary based on your use for Python.<br>And category 5 are arcane built-ins , which might be very handy when you need them but which many Python programmers are likely to never need.

Note for pedantic Pythonistas : I will be referring to all of these built-ins as functions , even though 27 of them aren't actually functions.

The commonly known built-in functions (which you likely already know about):

print

len

str

int

float

list

tuple

dict

set

range

The built-in functions which are often overlooked by newer Python programmers:

sum

enumerate

zip

bool

reversed

sorted

min

max

any

all

There are also 5 commonly overlooked built-ins which I recommend knowing about solely because they make debugging easier:

dir

vars

breakpoint

type

help

In addition to the 25 built-in functions above, we'll also briefly see the other 46 built-ins in the learn it later maybe learn it eventually and you likely don't need these sections.

The 10 commonly known built-in functions

If you've been writing Python code, these built-ins are likely familiar already.

print

You already know the print function.<br>Implementing hello world requires print.

You may not know about the various keyword arguments accepted by print though:

>>> words = ["Welcome", "to", "Python"]<br>>>> print(words)<br>['Welcome', 'to', 'Python']<br>>>> print(*words, end="!\n")<br>Welcome to Python!<br>>>> print(*words, sep="\n")<br>Welcome<br>to<br>Python

You can look up print on your own.

len

In Python, we don't write things like my_list.length() or my_string.length;<br>instead we strangely (for new Pythonistas at least) say len(my_list) and len(my_string).

>>> words = ["Welcome", "to", "Python"]<br>>>> len(words)

Regardless of whether you like this operator-like len function, you're stuck with it so you'll need to get used to it.

To make your own objects work with len, you can implement a __len__ method.

str

Unlike many other programming languages, Python doesn't have type coercion so you can't concatenate strings and numbers in Python.

>>> version = 3<br>>>> "Python " + version<br>Traceback (most recent call last):<br>File "", line 1, in<br>TypeError: can only concatenate str (not "int") to str

Python refuses to coerce that 3 integer to a string, so we need to manually do it ourselves, using the...

python built functions know print learn

Related Articles