The following are notes on 50 built-in Python functions, categorized for easier understanding.
Mathematical Functions
● abs(): Returns the absolute value of a number. For a complex number, it returns the
magnitude.
● bin(): Converts an integer to a binary string prefixed with '0b'.
● complex(): Creates a complex number from a real and optional imaginary part.
● divmod(): Returns a tuple containing the quotient and remainder of a division.
● float(): Converts a number or a string representation of a number to a floating-point
number.
● int(): Converts a number or a string into an integer.
● max(): Finds the largest item in an iterable or the largest of two or more arguments.
● min(): Finds the smallest item in an iterable or the smallest of two or more arguments.
● pow(): Returns the power of a number. It can also accept a third argument for the
modulus.
● round(): Rounds a number to a specified number of decimal places.
● sum(): Returns the sum of all items in an iterable, with an optional starting value.
Data Type Conversion & Constructors
● bool(): Converts a value to a boolean. It returns False for "falsy" values like 0, None,
empty strings, lists, or dictionaries.
● dict(): Creates a new dictionary. You can initialize it with key-value pairs from an iterable
or with keyword arguments.
● list(): Creates a new empty list or converts an iterable into a list.
● frozenset(): Returns an immutable version of a set object. Elements cannot be added or
removed.
● set(): Creates a new empty set or converts an iterable into a set, which automatically
removes duplicate elements.
● str(): Converts an object into its string representation.
● tuple(): Creates a new empty tuple or converts an iterable to a tuple.
Iterators & Iterables
● all(): Returns True if all elements of an iterable are true (or if the iterable is empty).
● any(): Returns True if any element of an iterable is true.
● enumerate(): Adds a counter to an iterable and returns it as an enumerate object. It's
often used in for loops to get both the index and the item.
● filter(): Constructs an iterator from elements of an iterable for which a function returns
True.
● iter(): Returns an iterator object from an iterable.
● len(): Returns the number of items in an object, such as a string, list, tuple, or dictionary.
● map(): Applies a given function to each item of an iterable and returns a map object (an
iterator).
● next(): Retrieves the next item from an iterator.
● range(): Generates an immutable sequence of numbers. It's commonly used in for loops.
● reversed(): Returns a reverse iterator for a sequence.
● sorted(): Returns a new sorted list from the items in an iterable. Unlike list.sort(), it does
not modify the original iterable.
● zip(): Combines multiple iterables into a single iterator of tuples, where the i-th tuple
contains the i-th element from each of the input iterables.
Utility Functions
● ascii(): Returns a string containing a printable representation of an object, escaping
non-ASCII characters with \x, \u, or \U escapes.
● callable(): Checks if an object can be called, such as a function or a method.
● chr(): Returns the character that corresponds to a specified Unicode value.
● dir(): Returns a list of valid attributes for an object. When called without an argument, it
returns a list of names in the current scope.
● eval(): Parses and evaluates a string as a Python expression, returning the result. Use
with caution as it can execute malicious code.
● exec(): Executes a block of Python code from a string or file. Unlike eval(), it does not
return a value.
● globals(): Returns a dictionary representing the current global symbol table.
● hash(): Returns the hash value of an object, if it is hashable. Hashable objects are used
as keys in dictionaries.
● help(): Invokes the built-in help system. It can be used to get documentation for a
module, function, or class.
● id(): Returns the unique identity of an object, which is its memory address.
● isinstance(): Checks if an object is an instance of a specified class or a subclass thereof.
● issubclass(): Checks if a class is a subclass of another class.
● locals(): Returns a dictionary representing the current local symbol table.
● open(): Opens a file and returns a corresponding file object. It's used for reading, writing,
or appending to a file.
● ord(): Returns an integer representing the Unicode code of a character.
● print(): Prints an object to the console. It can take multiple arguments, an optional
separator, and a custom end-of-line character.
● repr(): Returns a string containing a printable, "official" representation of an object. This
is often the string that would be used to recreate the object.
● slice(): Creates a slice object that can be used for slicing sequences like lists or tuples.
● type(): Returns the type of an object. You can also use it to dynamically create new
types.
● compile(): Compiles a source string into a code or AST object.
● classmethod(): Converts a method into a class method. The first argument of a class
method is the class itself.
● staticmethod(): Converts a method into a static method. Static methods do not receive
an implicit first argument.
● property(): Returns a property attribute. This is used for creating getters, setters, and
deleters for attributes in a class.
● super(): Returns a proxy object that allows you to refer to the parent class. It's commonly
used to call methods from a parent class that have been overridden in a child class.