Python Built-in Functions

Discover the powerful functions that Python provides out of the box and learn how they can streamline your programming workflow.

Core Built-in Functions Reference

Function Purpose Syntax Return Type Example Usage
abs() Returns the absolute value of a number abs(x) int | float | complex abs(-5)5
all() Returns True if all elements in an iterable are truthy all(iterable) bool all([True, True])True
any() Returns True if any element in an iterable is truthy any(iterable) bool any([False, True])True
ascii() Returns a printable ASCII representation of an object ascii(object) str ascii('ñ')'\\xf1'
bin() Converts an integer to a binary string bin(x) str bin(5)'0b101'
bool() Converts a value to a boolean bool(x) bool bool(0)False
breakpoint() Enters the debugger at the calling point breakpoint() None breakpoint()starts debugger
bytearray() Returns a new array of bytes bytearray([source[, encoding[, errors]]]) bytearray bytearray('abc', 'utf-8')
bytes() Returns a new immutable bytes object bytes([source[, encoding[, errors]]]) bytes bytes('abc', 'utf-8')
callable() Checks if an object appears callable callable(object) bool callable(len)True
chr() Returns the character for a given Unicode code point chr(i) str chr(65)'A'
classmethod() Converts a method to a class method classmethod(function) classmethod classmethod(my_method)
compile() Compiles source code into a code object compile(source, filename, mode) code compile('2+2', '', 'eval')
complex() Creates a complex number complex(real[, imag]) complex complex(1, 2)(1+2j)
delattr() Deletes an attribute from an object delattr(object, name) None delattr(obj, 'attr')
dict() Creates a dictionary dict(**kwargs) dict dict(a=1, b=2)
dir() Returns a list of valid attributes of an object dir([object]) list dir([])
divmod() Returns quotient and remainder divmod(a, b) tuple divmod(5, 2)(2, 1)
enumerate() Returns an enumerate object with index and value pairs enumerate(iterable, start=0) enumerate list(enumerate(['a', 'b']))
eval() Evaluates a string as a Python expression eval(expression[, globals[, locals]]) any eval('2+2')4
exec() Executes Python code dynamically exec(object[, globals[, locals]]) None exec("x=5")
filter() Filters elements using a function filter(function, iterable) filter list(filter(bool, [0, 1, 2]))
float() Converts a value to a floating point number float(x) float float("3.14")
format() Formats a value into a string format(value[, format_spec]) str format(255, 'x')'ff'
frozenset() Returns an immutable frozenset frozenset([iterable]) frozenset frozenset([1, 2])
getattr() Gets the value of an attribute getattr(object, name[, default]) any getattr(obj, 'attr')
globals() Returns the current global symbol table globals() dict globals()
hasattr() Checks if an object has an attribute hasattr(object, name) bool hasattr([], 'append')True
hash() Returns the hash value of an object hash(object) int hash("test")
help() Invokes the built-in help system help([object]) None help(len)
hex() Converts an integer to a hexadecimal string hex(x) str hex(255)'0xff'
id() Returns the identity of an object id(object) int id(42)
input() Reads a line from input input([prompt]) str input("Name: ")
int() Converts a value to an integer int(value, base=10) int int("123")123
isinstance() Checks if object is an instance of a class isinstance(object, classinfo) bool isinstance(42, int)True
issubclass() Checks if a class is a subclass of another issubclass(class, classinfo) bool issubclass(bool, int)True
iter() Returns an iterator from an object iter(object[, sentinel]) iterator iter([1, 2])
len() Returns the number of items in an object len(object) int len("hello")5
list() Creates a new list list([iterable]) list list("abc")['a', 'b', 'c']
locals() Returns the current local symbol table locals() dict locals()
map() Applies a function to each item in an iterable map(function, iterable) map list(map(str, [1, 2]))
max() Returns the largest item max(iterable, *[, key, default]) any max([1, 3, 2])3
memoryview() Returns a memory view object memoryview(object) memoryview memoryview(b'abc')
min() Returns the smallest item min(iterable, *[, key, default]) any min([1, 3, 2])1
next() Retrieves the next item from an iterator next(iterator[, default]) any next(iter([1,2]))
object() Returns a new featureless object object() object object()
oct() Converts an integer to an octal string oct(x) str oct(8)'0o10'
open() Opens a file open(file, mode='r') file object open('file.txt')
ord() Returns Unicode code point of a character ord(c) int ord('A')65
pow() Returns x to the power y pow(x, y[, z]) int | float pow(2, 3)8
print() Prints to standard output print(*objects, sep=' ', end='\n') None print("Hello")
property() Creates a property attribute property(fget=None, fset=None, fdel=None, doc=None) property property()
range() Returns an immutable sequence of numbers range(start, stop[, step]) range range(5)[0,1,2,3,4]
repr() Returns a string representation of an object repr(object) str repr("hi")"'hi'"
reversed() Returns a reversed iterator reversed(seq) iterator list(reversed([1, 2]))
round() Rounds a number round(number[, ndigits]) int | float round(3.1416, 2)3.14
set() Creates a new set set([iterable]) set set([1, 2])
setattr() Sets an attribute on an object setattr(object, name, value) None setattr(obj, 'attr', 5)
slice() Creates a slice object slice(start, stop[, step]) slice slice(1, 5, 2)
sorted() Returns a sorted list sorted(iterable, *, key=None, reverse=False) list sorted([3, 1, 2])[1, 2, 3]
staticmethod() Converts a method to a static method staticmethod(function) staticmethod staticmethod(my_method)
str() Converts a value to a string str(object='') str str(123)'123'
sum() Returns the sum of an iterable sum(iterable, start=0) int | float sum([1, 2, 3])6
super() Returns a proxy object for superclass method calls super([type[, object-or-type]]) super super().method()
tuple() Creates a tuple tuple([iterable]) tuple tuple("ab")('a','b')
type() Returns the type/class of an object type(object) type type(42)<class 'int'>
vars() Returns the __dict__ of an object vars([object]) dict vars(obj)
zip() Aggregates elements from iterables into tuples zip(*iterables) zip list(zip([1,2],[3,4]))
__import__() Imports a module __import__(name, globals=None, locals=None, fromlist=(), level=0) module __import__('math')