Python Functions (Built-In)

Last Updated on November 18, 2025 by Admin

IndexModulesDescriptionExample
1abs()Returns the absolute value of a number.print(abs(-7)) # 7
2aiter()Returns an asynchronous iterator for an async iterable.import asyncio; aiter_obj = aiter(asyncio.as_completed([asyncio.sleep(1)]))
3all()Returns True if all items in the iterable are truthy.print(all([True, 1, “non-empty”])) # True
4anext()Gets the next item from an async iterator.import asyncio; async def gen(): yield 1; print(asyncio.run(anext(gen().__aiter__())))
5any()Returns True if any item in the iterable is truthy.print(any([0, False, 5])) # True
6ascii()Returns a printable ASCII-only representation of an object.print(ascii(“café”)) # ‘caf\u00e9’
7bin()Converts an integer to a binary string (0b…).print(bin(10)) # ‘0b1010’
8bool()Converts a value to True or False.print(bool(“”)) # False
9breakpoint()Enters the debugger at the current program point.# breakpoint() # Starts debugger here (commented out to avoid pausing)
10bytearray()Creates a mutable sequence of bytes.print(bytearray(b”abc”)) # bytearray(b’abc’)
11bytes()Creates an immutable sequence of bytes.print(bytes([65, 66, 67])) # b’ABC’
12callable()Returns True if the object can be called like a function.print(callable(len)) # True
13chr()Returns the character for a Unicode code point.print(chr(65)) # ‘A’
14classmethod()Creates a method that receives the class instead of the instance.class A: @classmethod def f(cls): return cls.__name__; print(A.f())
15compile()Compiles Python source into a code object.code = compile(“print(‘Hi’)”, ““, “exec”); exec(code)
16complex()Creates a complex number.print(complex(2, 3)) # (2+3j)
17delattr()Deletes an attribute from an object.class C: x = 5; c = C(); delattr(c, “x”); print(hasattr(c, “x”)) # False
18dict()Creates a dictionary.print(dict(a=1, b=2)) # {‘a’: 1, ‘b’: 2}
19dir()Lists attributes of an object, module, or scope.print(dir([])) # List attributes and methods
20divmod()Returns a // b and a % b as a tuple.print(divmod(10, 3)) # (3, 1)
21enumerate()Adds counters to an iterable.print(list(enumerate([“a”, “b”]))) # [(0, ‘a’), (1, ‘b’)]
22eval()Evaluates a string as Python code and returns the result.print(eval(“1 + 2”)) # 3
23exec()Executes Python code without returning a value.exec(“x = 5”); print(x) # 5
24filter()Keeps items where the function returns True.print(list(filter(lambda x: x > 2, [1, 3, 5]))) # [3, 5]
25float()Converts a value to a floating-point number.print(float(“3.14”)) # 3.14
26format()Applies a formatting specification to a value.print(format(3.14159, “.2f”)) # ‘3.14’
27frozenset()Creates an immutable set.print(frozenset([1, 2, 2, 3])) # frozenset({1, 2, 3})
28getattr()Returns an attribute from an object.print(getattr(“abc”, “upper”)()) # ‘ABC’
29globals()Returns the global variable dictionary.print(“globals” in globals()) # True
30hasattr()Checks if an object has an attribute.print(hasattr([1, 2, 3], “append”)) # True
31hash()Returns the hash value of an object.print(hash(“hello”))
32help()Displays the built-in help system.# help(len) # Shows help (commented out to avoid long output)
33hex()Converts an integer to hexadecimal (0x…).print(hex(255)) # ‘0xff’
34id()Returns the unique identity (memory address) of an object.print(id(42)) # Unique object ID
35input()Reads a line of input from the user.# name = input(“Enter name: “) # Uncomment to read input
36int()Converts a value to an integer.print(int(“10”)) # 10
37isinstance()Checks if an object is an instance of a class.print(isinstance(5, int)) # True
38issubclass()Checks if a class is a subclass of another.print(issubclass(bool, int)) # True
39iter()Returns an iterator for an iterable object.it = iter([1, 2]); print(next(it)) # 1
40len()Returns the length of a container.print(len(“hello”)) # 5
41list()Creates a list.print(list(“abc”)) # [‘a’, ‘b’, ‘c’]
42locals()Returns a dictionary of local variables.print(“locals” in locals()) # True
43map()Applies a function to each item in an iterable.print(list(map(str, [1, 2]))) # [‘1’, ‘2’]
44max()Returns the largest item.print(max([1, 5, 3])) # 5
45memoryview()Creates a memory view object for byte-level access.print(memoryview(b”abc”)[1]) # 98 (ASCII of ‘b’)
46min()Returns the smallest item.print(min([1, 5, 3])) # 1
47next()Returns the next value from an iterator.it = iter([1, 2]); print(next(it)) # 1
48object()Creates a new base object instance.o = object(); print(type(o)) #
49oct()Converts an integer to octal (0o…).print(oct(8)) # ‘0o10’
50open()Opens a file and returns a file object.with open(__file__) as f: print(f.readline().strip()) # Reads first line this script
51ord()Returns the Unicode code point of a character.print(ord(“A”)) # 65
52pow()Computes a ** b (with optional modulo).print(pow(2, 3)) # 8
53print()Prints objects to standard output.print(“Hello, World!”)
54property()Defines a managed attribute in a class.class C: @property def x(self): return 5; print(C().x)
55range()Creates a sequence of numbers.print(list(range(3))) # [0, 1, 2]
56repr()Returns the official string representation of an object.print(repr(“abc”)) # “‘abc'”
57reversed()Returns a reversed iterator for a sequence.print(list(reversed([1, 2, 3]))) # [3, 2, 1]
58round()Rounds a number to a specified number of digits.print(round(3.14159, 2)) # 3.14
59set()Creates a set.print(set([1, 2, 2, 3])) # {1, 2, 3}
60setattr()Sets an attribute on an object.class C: pass; c = C(); setattr(c, “x”, 10); print(c.x)
61slice(),Creates a slice object for indexing.s = slice(1, 4); print([0,1,2,3,4][s]) # [1, 2, 3]
62sorted()Returns a new sorted list.print(sorted([3, 1, 2])) # [1, 2, 3]
63staticmethod()Creates a method that does not receive self or cls.class C: @staticmethod def f(): return 5; print(C.f())
64str()Converts a value to a string.print(str(123)) # ‘123’
65sum()Returns the sum of items.print(sum([1, 2, 3])) # 6
66super()Provides access to parent class methods.class A: def f(self): return “A”; class B(A): def f(self): return super().f() + “B”; print(B().f())
67tuple()Creates a tuple.print(tuple([1, 2, 3])) # (1, 2, 3)
68type()Returns the type of an object or creates a new type.print(type(5)) #
69vars()Returns the __dict__ attribute of an object.class C: def __init__(self): self.x = 5; print(vars(C()))
70zip()Combines items from iterables into tuples.print(list(zip([1, 2], [‘a’, ‘b’]))) # [(1, ‘a’), (2, ‘b’)]
71__import__()Low-level import used internally by import.math_mod = __import__(“math”); print(math_mod.sqrt(16))