Python's most commonly used built-in functions, organized by alphabet. Each function is explained with a brief description, an example, and some fun ๐ emojis to make it easier and more enjoyable to learn.
๐ค A
abs()
โ Absolute value
Returns the absolute value of a number
abs(-7) # 7
all()
โ Checks if all items are True
Returns
True
if all elements in an iterable are true
all([1, 2, 3]) # True
any()
โ Any item True?
Returns
True
if at least one element is True
any([False, 0, 5]) # True
ascii()
โ String representation
Returns a string containing a printable representation
ascii("cafรฉ") # "'caf\\xe9'"
๐งฎ B
bin()
โ Binary representation
Returns binary version of a number
bin(5) # '0b101'
bool()
โ Boolean value
Converts a value to Boolean (
True
orFalse
)
bool(0) # False
bytearray()
โ Mutable byte sequence
Creates a mutable array of bytes
bytearray('hello', 'utf-8') # bytearray(b'hello')
bytes()
โ Immutable byte sequence
Creates an immutable bytes object
bytes('hello', 'utf-8') # b'hello'
๐ C
chr()
โ Character from ASCII
Returns the character corresponding to an ASCII code
chr(65) # 'A'
complex()
โ Complex numbers
Creates a complex number
complex(2, 3) # (2+3j)
๐๏ธ D
delattr()
โ Delete attribute
Deletes an attribute from an object
class Car:
color = "red"
delattr(Car, "color")
dict()
โ Dictionary
Creates a dictionary
dict(name="Alice", age=25) # {'name': 'Alice', 'age': 25}
dir()
โ List attributes
Returns list of attributes of an object
dir([]) # Shows list methods like append(), sort(), etc.
divmod()
โ Division & Modulus
Returns quotient and remainder
divmod(10, 3) # (3, 1)
๐ E
enumerate()
โ Index + Value
Returns index and value pairs
for i, val in enumerate(['a','b','c']): print(i, val)
eval()
โ Evaluate expression
Evaluates a string as Python code
eval("2 + 3") # 5
exec()
โ Execute code
Executes a block of Python code
exec("x = 5\nprint(x)") # 5
๐งน F
filter()
โ Filter items
Filters iterable using a function
list(filter(lambda x: x > 3, [1,2,3,4,5])) # [4,5]
float()
โ Float conversion
Converts a value to float
float("3.14") # 3.14
format()
โ Format values
Formats a string
"{} {}".format("Hello", "World") # 'Hello World'
frozenset()
โ Immutable set
Creates an immutable set
frozenset([1,2,3]) # frozenset({1,2,3})
๐ก G
getattr()
โ Get attribute
Returns the value of a named attribute
class Dog: name = "Buddy"
getattr(Dog, "name") # 'Buddy'
globals()
โ Global variables
Returns dictionary of global variables
globals()
๐ H
hasattr()
โ Check attribute
Returns
True
if object has that attribute
hasattr(str, "upper") # True
hash()
โ Hash value
Returns hash of an object
hash("hello") # Some integer
help()
โ Documentation
Shows help documentation
help(list)
hex()
โ Hexadecimal
Returns hexadecimal representation
hex(255) # '0xff'
๐ข I
id()
โ Identity
Returns memory address of object
id("hello")
input()
โ User input
Takes input from user
name = input("Enter name: ")
int()
โ Integer conversion
Converts to integer
int("123") # 123
isinstance()
โ Type check
Returns
True
if object is instance of class
isinstance(5, int) # True
issubclass()
โ Inheritance check
Returns
True
if class is subclass
issubclass(bool, int) # True
iter()
โ Iterator
Returns iterator object
it = iter([1,2,3])
next(it) # 1
๐ L
len()
โ Length
Returns length of object
len("hello") # 5
list()
โ List
Converts to list
list((1,2,3)) # [1,2,3]
locals()
โ Local variables
Returns local variable dict
locals()
๐ M
map()
โ Apply function
Applies function to all items
list(map(lambda x: x.upper(), ["a"])) # ['A']
max()
โ Maximum
Returns maximum value
max([1,2,3]) # 3
min()
โ Minimum
Returns minimum value
min([1,2,3]) # 1
memoryview()
โ Memory view
Access internal data without copying
mv = memoryview(b'Hello')
โญ๏ธ N
next()
โ Next item
Returns next item from iterator
it = iter([1,2])
next(it) # 1
๐ฆ O
object()
โ Base class
Returns a new featureless object
obj = object()
oct()
โ Octal
Returns octal representation
oct(8) # '0o10'
open()
โ File opener
Opens a file
with open("file.txt") as f: content = f.read()
ord()
โ ASCII code
Returns ASCII code for a character
ord('A') # 65
๐ฅ P
pow()
โ Power
Raises a number to a power
pow(2, 3) # 8
print()
โ Output
Prints output to console
print("Hello!")
property()
โ Property
Used in classes to create managed attributes
class Circle:
def __init__(self, radius):
self._radius = radius
@property
def radius(self):
return self._radius
๐ R
range()
โ Range of numbers
Generates sequence of numbers
list(range(1, 5)) # [1,2,3,4]
repr()
โ Representation
Returns string representation
repr("hello") # "'hello'"
reversed()
โ Reverse iterator
Returns reversed iterator
list(reversed([1,2,3])) # [3,2,1]
round()
โ Round number
Rounds a number to n digits
round(3.1415, 2) # 3.14
๐ ๏ธ S
set()
โ Set
Creates a set
set([1,2,2]) # {1,2}
setattr()
โ Set attribute
Sets an attribute on an object
class Car: pass
setattr(Car, "color", "blue")
slice()
โ Slice object
Represents slicing
s = slice(1, 4)
[0,1,2,3,4][s] # [1,2,3]
sorted()
โ Sort
Returns sorted list
sorted([3,1,2]) # [1,2,3]
staticmethod()
โ Static method
Marks a method as static
class Math:
@staticmethod
def add(a, b): return a + b
str()
โ String
Converts to string
str(123) # '123'
sum()
โ Summation
Adds all items
sum([1,2,3]) # 6
super()
โ Parent class
Calls parent class method
class Child(Parent):
def __init__(self):
super().__init__()
๐ฆ T
tuple()
โ Tuple
Converts to tuple
tuple([1,2]) # (1,2)
type()
โ Type
Returns type of object
type(5) # <class 'int'>
๐ฅ V
vars()
โ Object attributes
Returns
__dict__
of an object
class Person: pass
p = Person()
vars(p) # {}
๐ฆ Z
zip()
โ Pair items
Pairs items from multiple iterables
list(zip([1,2], ['a','b'])) # [(1,'a'), (2,'b')]
๐ง Special
__import__()
โ Import module
Used by import system internally
math = __import__('math') # Same as import math
๐ Summary Table
Function | Use |
---|---|
abs() , pow() , round()
|
Math operations |
str() , int() , float()
|
Type conversion |
list() , dict() , set()
|
Data structure creation |
map() , filter() , zip()
|
Functional tools |
len() , max() , min()
|
Size/value checks |
dir() , help() , type()
|
Debugging & introspection |
Top comments (1)
Awesome cheat sheet! Iโd love to see a similar guide covering Pythonโs built-in exceptions and common error handling tips next.