Built-in Functions

Python's built-in functions are available without importing any modules. This reference covers all built-in functions with their parameters, return values, and practical usage examples.

Mathematical Functions

FunctionPurposeParametersReturn TypeExampleDescription
abs()Absolute valueabs(x)Numberabs(-5) # 5Returns absolute value of a number
divmod()Division and modulodivmod(a, b)Tupledivmod(10, 3) # (3, 1)Returns quotient and remainder
max()Maximum valuemax(iterable) or max(a, b, ...)Anymax([1, 5, 3]) # 5Returns largest item
min()Minimum valuemin(iterable) or min(a, b, ...)Anymin([1, 5, 3]) # 1Returns smallest item
pow()Power operationpow(base, exp, mod=None)Numberpow(2, 3) # 8Returns base raised to power
round()Round numberround(number, ndigits=None)Numberround(3.14159, 2) # 3.14Rounds to specified decimal places
sum()Sum of sequencesum(iterable, start=0)Numbersum([1, 2, 3]) # 6Returns sum of all items

Type Conversion Functions

FunctionPurposeParametersReturn TypeExampleDescription
bool()Convert to booleanbool(x)boolbool(1) # TrueConverts value to boolean
int()Convert to integerint(x, base=10)intint("123") # 123Converts to integer
float()Convert to floatfloat(x)floatfloat("3.14") # 3.14Converts to floating point
str()Convert to stringstr(object)strstr(123) # "123"Converts to string representation
list()Convert to listlist(iterable)listlist("abc") # ['a', 'b', 'c']Converts iterable to list
tuple()Convert to tupletuple(iterable)tupletuple([1, 2, 3]) # (1, 2, 3)Converts iterable to tuple
set()Convert to setset(iterable)setset([1, 2, 2, 3]) # {1, 2, 3}Converts iterable to set
dict()Create dictionarydict(**kwargs)dictdict(a=1, b=2) # {'a': 1, 'b': 2}Creates dictionary
bytes()Convert to bytesbytes(source, encoding)bytesbytes("hello", "utf-8")Converts to bytes object

Sequence and Iteration Functions

FunctionPurposeParametersReturn TypeExampleDescription
len()Get lengthlen(s)intlen([1, 2, 3]) # 3Returns length of sequence
range()Create rangerange(start, stop, step)rangelist(range(5)) # [0, 1, 2, 3, 4]Creates sequence of numbers
enumerate()Add indicesenumerate(iterable, start=0)enumeratelist(enumerate(['a', 'b'])) # [(0, 'a'), (1, 'b')]Returns indexed pairs
zip()Combine iterableszip(*iterables)ziplist(zip([1, 2], ['a', 'b'])) # [(1, 'a'), (2, 'b')]Combines multiple iterables
reversed()Reverse sequencereversed(seq)iteratorlist(reversed([1, 2, 3])) # [3, 2, 1]Returns reversed iterator
sorted()Sort sequencesorted(iterable, key=None, reverse=False)listsorted([3, 1, 2]) # [1, 2, 3]Returns sorted list
filter()Filter itemsfilter(function, iterable)filterlist(filter(lambda x: x > 0, [-1, 0, 1, 2])) # [1, 2]Filters items by function
map()Apply functionmap(function, iterable)maplist(map(str.upper, ['a', 'b'])) # ['A', 'B']Applies function to each item
any()Test any trueany(iterable)boolany([False, True, False]) # TrueTrue if any element is true
all()Test all trueall(iterable)boolall([True, True, False]) # FalseTrue if all elements are true

Object and Attribute Functions

FunctionPurposeParametersReturn TypeExampleDescription
getattr()Get attributegetattr(object, name, default=None)Anygetattr(obj, 'attr', 'default')Gets object attribute safely
setattr()Set attributesetattr(object, name, value)Nonesetattr(obj, 'attr', 'value')Sets object attribute
hasattr()Check attributehasattr(object, name)boolhasattr(obj, 'attr') # True/FalseChecks if object has attribute
delattr()Delete attributedelattr(object, name)Nonedelattr(obj, 'attr')Deletes object attribute
callable()Check callablecallable(object)boolcallable(len) # TrueChecks if object is callable
isinstance()Check instanceisinstance(object, classinfo)boolisinstance([], list) # TrueChecks object type
issubclass()Check subclassissubclass(class, classinfo)boolissubclass(bool, int) # TrueChecks class inheritance
type()Get typetype(object)typetype([]) # <class 'list'>Returns object type
id()Get object IDid(object)intid([]) # 140234567890Returns unique object identifier
vars()Get variablesvars(object=None)dictvars(obj) # {'attr': 'value'}Returns object's __dict__

Input/Output Functions

FunctionPurposeParametersReturn TypeExampleDescription
print()Print outputprint(*values, sep=' ', end='\n', file=sys.stdout)Noneprint("Hello", "World")Prints values to output
input()Get user inputinput(prompt='')strname = input("Name: ")Gets string input from user
open()Open fileopen(file, mode='r', encoding=None)file objectopen('file.txt', 'r')Opens file for reading/writing

Advanced Functions

FunctionPurposeParametersReturn TypeExampleDescription
eval()Evaluate expressioneval(expression, globals=None, locals=None)Anyeval("2 + 3") # 5Evaluates Python expression
exec()Execute codeexec(object, globals=None, locals=None)Noneexec("x = 5")Executes Python code
compile()Compile codecompile(source, filename, mode)code objectcompile("x + 1", "", "eval")Compiles source into code object
globals()Global namespaceglobals()dictglobals()['__name__']Returns global symbol table
locals()Local namespacelocals()dictlocals()Returns local symbol table
dir()List attributesdir(object=None)listdir([]) # ['append', 'clear', ...]Lists object attributes
help()Get helphelp(object=None)Nonehelp(len)Shows help documentation
hash()Get hashhash(object)inthash("hello") # 2314058222102390712Returns object hash value
iter()Create iteratoriter(object, sentinel=None)iteratoriter([1, 2, 3])Creates iterator object
next()Get next itemnext(iterator, default=None)Anynext(iter([1, 2, 3])) # 1Gets next item from iterator
repr()String representationrepr(object)strrepr([1, 2, 3]) # "[1, 2, 3]"Returns string representation
ascii()ASCII representationascii(object)strascii("café") # "'caf\\xe9'"Returns ASCII string representation
bin()Binary representationbin(x)strbin(10) # '0b1010'Converts integer to binary string
hex()Hexadecimal representationhex(x)strhex(255) # '0xff'Converts integer to hex string
oct()Octal representationoct(x)stroct(8) # '0o10'Converts integer to octal string
ord()Character codeord(c)intord('A') # 65Returns Unicode code of character
chr()Character from codechr(i)strchr(65) # 'A'Returns character from Unicode code

Memory and Object Functions

FunctionPurposeParametersReturn TypeExampleDescription
object()Create objectobject()objectobj = object()Creates new object instance
super()Parent class accesssuper(type=None, object=None)supersuper().__init__()Access parent class methods
property()Create propertyproperty(fget=None, fset=None, fdel=None, doc=None)propertyprop = property(getter, setter)Creates property descriptor
staticmethod()Static methodstaticmethod(function)staticmethod@staticmethodCreates static method
classmethod()Class methodclassmethod(function)classmethod@classmethodCreates class method

Best Practices

  • Use type conversion functions: Prefer int(), str(), etc. over manual conversion
  • Leverage sequence functions: Use enumerate(), zip(), sorted() for cleaner code
  • Check before accessing: Use hasattr() before getattr() for safety
  • Prefer built-ins: Built-in functions are optimized and typically faster
  • Know your iterators: Understand the difference between map(), filter(), and list comprehensions
  • Use any() and all(): More readable than manual loops for boolean testing

Was this helpful?

😔Poor
🙁Fair
😊Good
😄Great
🤩Excellent