Tutorials › Python Tutorial › Python Built-in Functions Reference

Python Built-in Functions Reference

8 min read · Lesson 23 of 24

Python has around 70 built-in functions that are always available, with no import needed. This page lists the ones you are most likely to use, grouped by job. Use it as a quick reference while you code.

Input and output

FunctionDescriptionExample
print()Shows values on the screenprint("Habari", 5)
input()Reads a line typed by the user (not available in our browser editor)name = input("Name: ")
open()Opens a file and returns a file objectopen("data.txt", "r")
format()Formats a value with a format specifierformat(1234.5, ",.2f") → '1,234.50'
repr()Returns a developer-friendly text form of a valuerepr("hi") → "'hi'"

Types and conversion

FunctionDescriptionExample
int()Converts to a whole numberint("42") → 42
float()Converts to a decimal numberfloat("3.5") → 3.5
str()Converts to textstr(100) → '100'
bool()Converts to True or Falsebool("") → False
list()Creates a listlist("abc") → ['a', 'b', 'c']
tuple()Creates a tupletuple([1, 2]) → (1, 2)
set()Creates a set (removes duplicates)set([1, 1, 2]) → {1, 2}
dict()Creates a dictionarydict(a=1) → {'a': 1}
complex()Creates a complex numbercomplex(2, 3) → (2+3j)
type()Returns the type of a valuetype(5) → <class 'int'>
isinstance()Checks if a value is of a given typeisinstance(5, int) → True

Numbers and maths

FunctionDescriptionExample
abs()Absolute (positive) valueabs(-7) → 7
round()Rounds to a number of decimal placesround(3.14159, 2) → 3.14
pow()Raises to a powerpow(2, 5) → 32
divmod()Floor division and remainder togetherdivmod(17, 5) → (3, 2)
sum()Adds up the items of an iterablesum([1, 2, 3]) → 6
min()Smallest itemmin(4, 9, 2) → 2
max()Largest itemmax(4, 9, 2) → 9
bin()Binary text form of an integerbin(5) → '0b101'
hex()Hexadecimal text form of an integerhex(255) → '0xff'
oct()Octal text form of an integeroct(8) → '0o10'

Sequences and iteration

FunctionDescriptionExample
len()Number of itemslen("Kenya") → 5
range()A sequence of numberslist(range(3)) → [0, 1, 2]
enumerate()Pairs each item with a counterlist(enumerate("ab")) → [(0, 'a'), (1, 'b')]
zip()Combines several iterables item by itemlist(zip([1, 2], "ab")) → [(1, 'a'), (2, 'b')]
sorted()Returns a new sorted listsorted([3, 1, 2]) → [1, 2, 3]
reversed()Returns the items in reverse orderlist(reversed([1, 2, 3])) → [3, 2, 1]
map()Applies a function to every itemlist(map(str.upper, ["a", "b"])) → ['A', 'B']
filter()Keeps items for which a function is truelist(filter(None, [0, 1, 2])) → [1, 2]
any()True if at least one item is trueany([0, 0, 1]) → True
all()True if every item is trueall([1, 1, 0]) → False
iter()Gets an iterator from an iterableit = iter([1, 2])
next()Gets the next item from an iteratornext(iter([1, 2])) → 1

Text and characters

FunctionDescriptionExample
chr()Character for a Unicode codechr(65) → 'A'
ord()Unicode code for a characterord("A") → 65
ascii()Text form with non-ASCII characters escapedprint(ascii("é")) shows '\xe9'

Objects and classes

FunctionDescriptionExample
id()Unique identity number of an objectid(x)
dir()Lists the names an object or module containsdir(str)
help()Shows built-in documentationhelp(len)
hasattr()Checks if an object has an attributehasattr("hi", "upper") → True
getattr()Gets an attribute by namegetattr("hi", "upper")() → 'HI'
setattr()Sets an attribute by namesetattr(obj, "age", 30)
callable()Checks if something can be calledcallable(print) → True
super()Accesses the parent classsuper().__init__()
issubclass()Checks if a class inherits from anotherissubclass(bool, int) → True

Seeing them in action

Example PYTHON
scores = [72, 88, 95, 61]
print(len(scores), sum(scores), min(scores), max(scores))
print(sorted(scores, reverse=True))
print(any(s < 65 for s in scores), all(s >= 60 for s in scores))
print(list(zip(["Amina", "Baraka"], scores)))
Result
4 316 61 95
[95, 88, 72, 61]
True True
[('Amina', 72), ('Baraka', 88)]
Try it Yourself »
Example PYTHON
print(round(1234.5678, 2), abs(-15), divmod(100, 7))
print(int("250") + float("0.5"), str(2025) + "!")
print(ord("K"), chr(75), bin(10), hex(255))
print(isinstance(3.0, float), type([]).__name__)
Result
1234.57 15 (14, 2)
250.5 2025!
75 K 0b1010 0xff
True list
Try it Yourself »
Tip: Type help(function_name) in the Python shell (for example help(sorted)) to read the official description of any built-in function.

Related lessons: Numbers and Casting, Lists, For Loops, Lambda and Comprehensions.

Ready to test yourself? Take the Python Quiz.

Sign in or create a free account to track progress, earn XP, badges and a certificate.