This page is a one-stop shop for Python’s important built-in modules and functions, as well as third-party libraries. This is a simplified version of reference documentation for Python programming. I created simple guides on all the important Python modules and functions and added them to this page. Click on the links to read the correspoding guides.
Python Built-in Modules
Python provides a rich set of built-in modules that extend its capabilities, making it a versatile language for various applications. These modules cover a wide range of functionalities, from handling data types and performing mathematical operations to managing files and handling network communication.
Text Processing Modules
Module | Description |
---|---|
string | Provides a collection of string operations and constants. |
re | Supports regular expressions for advanced string searching and manipulation. |
difflib | Provides tools for comparing sequences, especially useful for comparing text. |
textwrap | Helps format text by wrapping and filling it. |
unicodedata | Provides access to the Unicode Character Database. |
stringprep | Implements the StringPrep algorithm for preparing Unicode strings. |
Data Types Modules
Module | Description |
---|---|
collections | Implements specialized container datatypes. |
heapq | Provides an implementation of the heap queue algorithm. |
bisect | Supports array bisection algorithms. |
array | Defines a sequence type for efficient storage of basic C-style data types. |
weakref | Provides support for weak references to objects. |
types | Defines names for built-in types that aren’t exposed as built-in functions. |
copy | Provides shallow and deep copy operations. |
pprint | Pretty-prints Python data structures. |
reprlib | Provides a means to produce object representations with limits on size. |
enum | Supports enumerations, which are a set of symbolic names bound to unique, constant values. |
Numeric and Mathematical Modules
Module | Description |
---|---|
math | Provides access to mathematical functions. |
cmath | Provides mathematical functions for complex numbers. |
decimal | Implements decimal floating-point arithmetic. |
fractions | Supports rational number arithmetic. |
random | Implements pseudo-random number generators. |
statistics | Provides functions for mathematical statistics of numeric data. |
File and Directory Access Modules
Module | Description |
---|---|
pathlib | Offers classes representing filesystem paths with semantics appropriate for different operating systems. |
os | Provides a way of using operating system-dependent functionality. |
shutil | Offers high-level operations on files and collections of files. |
glob | Finds all the pathnames matching a specified pattern. |
fnmatch | Provides Unix shell-style wildcard pattern matching. |
tempfile | Generates temporary files and directories. |
Data Compression and Archiving Modules
Module | Description |
---|---|
zlib | Provides compression compatible with the gzip format. |
gzip | Supports reading and writing GNU zip files. |
zipfile | Manages ZIP archives. |
Data Persistence Modules
Module | Description |
---|---|
csv | Reads and writes tabular data in CSV format. |
configparser | Provides configuration file parsing. |
json | Parses JSON (JavaScript Object Notation). |
pickle | Serializes and de-serializes Python object structures. |
Cryptographic Services Modules
Module | Description |
---|---|
hashlib | Provides common interfaces to secure hash and message digest algorithms. |
secrets | Provides functions for generating secure random numbers for managing secrets. |
Networking and Interprocess Communication Modules
Module | Description |
---|---|
socket | Provides low-level networking interface. |
ssl | Provides TLS/SSL wrapper for socket objects. |
select | Provides select and poll functions to monitor multiple streams. |
selectors | Provides high-level I/O multiplexing. |
Concurrency and Parallelism Modules
Module | Description |
---|---|
threading | Higher-level threading interface. |
multiprocessing | Supports process-based parallelism. |
concurrent.futures | Provides a high-level interface for asynchronously executing callables. |
Internet Data Handling Modules
Module | Description |
---|---|
Manages email messages, including MIME. | |
http | Provides classes for HTTP requests and responses. |
xml | Provides tools for processing XML documents. |
html | Provides utilities for manipulating HTML. |
Miscellaneous Modules
Module | Description |
---|---|
sys | Provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. |
time | Provides functions for working with time. |
argparse | Parses command-line arguments. |
getopt | C-style parser for command-line options. |
logging | Provides a flexible framework for emitting log messages. |
Python Array Methods
Python provides a variety of methods to manipulate and operate on arrays. These methods make it easy to perform common tasks such as adding, removing, and accessing elements in an array. Below is a list of some commonly used array methods, along with their descriptions and links to detailed guides for each method.
Method | Description |
---|---|
append() | Adds an element to the end of the array. |
buffer_info() | Returns a tuple containing the memory address and the length of the buffer used to hold array contents. |
byteswap() | Swaps the byte order of the array elements. |
count() | Returns the number of occurrences of the specified element in the array. |
extend() | Adds the elements of an iterable to the end of the array. |
frombytes() | Converts a byte array into an array. |
fromfile() | Reads array elements from a file object. |
fromlist() | Appends items from the list to the end of the array. |
fromunicode() | Extends the array with items from the Unicode string. |
index() | Returns the index of the first occurrence of the specified element. |
insert() | Inserts an element at the specified position. |
pop() | Removes and returns the element at the specified position. |
remove() | Removes the first occurrence of the specified element. |
reverse() | Reverses the order of the elements in the array. |
tofile() | Writes the array to a file as a sequence of bytes. |
tolist() | Converts the array to a list. |
tounicode() | Converts the array to a Unicode string. |
Python List Methods
Python provides a variety of methods to manipulate and operate on lists. These methods make it easy to perform common tasks such as adding, removing, and organizing elements in a list. Below is a list of some commonly used list methods, along with their descriptions and links to detailed guides for each method.
Method | Description |
---|---|
append() | Adds an element to the end of the list. |
clear() | Removes all elements from the list. |
copy() | Returns a copy of the list. |
count() | Returns the number of elements with the specified value. |
extend() | Adds the elements of an iterable to the end of the list. |
index() | Returns the index of the first element with the specified value. |
pop() | Removes the element at the specified position and returns it. |
remove() | Removes the first item with the specified value. |
reverse() | Reverses the order of the list. |
sort() | Sorts the list in ascending order by default. |
Python Set Methods
Python provides a variety of methods to manipulate and operate on sets. These methods make it easy to perform common tasks such as adding, removing, and combining elements in a set. Below is a list of some commonly used set methods, along with their descriptions and links to detailed guides for each method.
Method | Description |
---|---|
add() | Adds an element to the set. |
clear() | Removes all elements from the set. |
copy() | Returns a copy of the set. |
difference() | Returns a set containing the difference between two or more sets. |
difference_update() | Removes the items in this set that are also included in another, specified set. |
discard() | Removes the specified item. |
intersection() | Returns a set that is the intersection of two other sets. |
intersection_update() | Removes the items in this set that are not present in other, specified sets. |
isdisjoint() | Returns whether two sets have a null intersection. |
issubset() | Returns whether another set contains this set. |
issuperset() | Returns whether this set contains another set. |
pop() | Removes an element from the set. |
remove() | Removes the specified element. |
symmetric_difference() | Returns a set with the symmetric differences of two sets. |
symmetric_difference_update() | Inserts the symmetric differences from this set and another. |
union() | Returns a set containing the union of sets. |
update() | Updates the set with the union of this set and others. |
Python Tuple Methods
Python tuples provide a couple of methods to operate on and extract information from the tuple elements. Below is a list of the commonly used tuple methods, along with their descriptions and links to detailed guides for each method.
Method | Description |
---|---|
count() | Returns the number of times a specified value appears in the tuple. |
index() | Returns the index of the first occurrence of the specified value. |
Python Dictionary Methods
Python dictionaries provide a variety of methods to manipulate and operate on key-value pairs. These methods make it easy to perform common tasks such as adding, removing, and accessing elements in a dictionary. Below is a list of some commonly used dictionary methods, along with their descriptions and links to detailed guides for each method.
Python Dictionary Methods Table
Method | Description |
---|---|
clear() | Removes all elements from the dictionary. |
copy() | Returns a copy of the dictionary. |
fromkeys() | Creates a dictionary from the given sequence of keys and a value. |
get() | Returns the value of the specified key. |
items() | Returns a view object containing the dictionary’s key-value pairs. |
keys() | Returns a view object containing the dictionary’s keys. |
pop() | Removes the specified key and returns the corresponding value. |
popitem() | Removes and returns the last key-value pair inserted into the dictionary. |
setdefault() | Returns the value of the specified key. If the key does not exist, inserts the key with the specified value. |
update() | Updates the dictionary with the specified key-value pairs. |
values() | Returns a view object containing the dictionary’s values. |
Python String Methods
Python provides a set of built-in methods to manipulate and operate on strings. These methods make it easy to perform common tasks such as searching, splitting, and formatting strings. Below is a list of some commonly used string methods, along with their descriptions and links to detailed guides for each method.
Method | Description |
---|---|
format() | Formats specified values in a string. |
split() | Splits a string into a list where each word is a list item. |
join() | Joins the elements of an iterable into a single string, separated by the string that called the method. |
strip() | Removes any leading and trailing characters (space is the default). |
replace() | Replaces a specified phrase with another specified phrase. |
lower() | Converts a string into lowercase. |
upper() | Converts a string into upper case. |
count() | Returns the number of times a specified value appears in the string. |
find() | Searches the string for a specified value and returns the position of where it was found. |
rsplit() | Splits a string into a list, starting from the right. |
splitlines() | Splits a string at line breaks and returns a list. |
center() | Returns a centered string. |
zfill() | Fills the string with a specified number of 0 values at the beginning. |
startswith() | Returns true if the string starts with the specified value. |
endswith() | Returns true if the string ends with the specified value. |
translate() | Returns a string where some specified characters are replaced with the character described in a dictionary or mapping table. |
casefold() | Converts a string into lowercase. |
capitalize() | Converts the first character to upper case. |
title() | Converts the first character of each word to upper case. |
expandtabs() | Sets the tab size of the string. |
islower() | Returns true if all characters in the string are lowercase. |
isupper() | Returns true if all characters in the string are upper case. |
isnumeric() | Returns true if all characters in the string are numeric. |
isdecimal() | Returns true if all characters in the string are decimals. |
isdigit() | Returns true if all characters in the string are digits. |
isprintable() | Returns true if all characters in the string are printable. |
isspace() | Returns true if all characters in the string are whitespaces. |
istitle() | Returns true if the string follows the rules of a title. |
encode() | Returns an encoded version of the string. |
maketrans() | Returns a translation table to be used in translations. |
format_map() | Formats specified values in a string using a dictionary. |
index() | Searches the string for a specified value and returns the position of where it was found. |
isalnum() | Returns true if all characters in the string are alphanumeric. |
isalpha() | Returns true if all characters in the string are in the alphabet. |
isidentifier() | Returns true if the string is a valid identifier. |
ljust() | Returns a left-justified version of the string. |
partition() | Returns a tuple where the string is parted into three parts. |
rfind() | Searches the string for a specified value and returns the last position of where it was found. |
rindex() | Searches the string for a specified value and returns the last position of where it was found. |
rjust() | Returns a right justified version of the string. |
rpartition() | Returns a tuple where the string is parted into three parts. |
rstrip() | Removes any trailing characters (space is the default). |
swapcase() | Swaps cases, the lower case becomes the upper case and vice versa. |
title() | Converts the first character of each word to upper case. |
translate() | Returns a string where some specified characters are replaced with the character described in a dictionary or mapping table. |
upper() | Converts a string into upper case. |
zfill() | Fills the string with a specified number of 0 values at the beginning. |
Python Built-in Functions
Python provides a comprehensive set of built-in functions that can be used to perform various tasks. These functions are always available and do not require any imports to use them. Below is a list of some commonly used built-in functions, along with their descriptions and links to detailed guides for each function.
Function | Description |
---|---|
abs() | Returns the absolute value of a number. |
all() | Returns True if all elements of an iterable are true. |
any() | Returns True if any element of an iterable is true. |
ascii() | Returns a string containing a printable representation of an object. |
bin() | Converts an integer to a binary string. |
bool() | Converts a value to a Boolean. |
bytearray() | Returns a byte array object. |
bytes() | Returns a bytes object. |
callable() | Returns True if the object appears callable. |
chr() | Returns a string representing a character from an integer. |
classmethod() | Converts a method into a class method. |
compile() | Compiles source into a code or AST object. |
complex() | Returns a complex number. |
delattr() | Deletes an attribute from an object. |
dict() | Creates a dictionary. |
dir() | Tries to return a list of valid attributes of an object. |
divmod() | Returns a tuple containing the quotient and remainder when dividing two numbers. |
enumerate() | Returns an enumerate object. |
eval() | Evaluates a given expression. |
exec() | Executes the given code. |
filter() | Constructs an iterator from elements of an iterable for which a function returns true. |
float() | Returns a floating-point number. |
format() | Formats a specified value. |
frozenset() | Returns a frozenset object. |
getattr() | Returns the value of the named attribute of an object. |
globals() | Returns a dictionary representing the current global symbol table. |
hasattr() | Returns True if the object has the specified attribute. |
hash() | Returns the hash value of an object. |
help() | Invokes the built-in help system. |
hex() | Converts an integer to a hexadecimal string. |
id() | Returns the identity of an object. |
input() | Reads a line from input. |
int() | Converts a value to an integer. |
isinstance() | Checks if an object is an instance of a class. |
issubclass() | Checks if a class is a subclass of another class. |
iter() | Returns an iterator object. |
len() | Returns the length of an object. |
list() | Creates a list. |
locals() | Updates and returns a dictionary representing the current local symbol table. |
map() | Applies a function to every item of an iterable. |
max() | Returns the largest item in an iterable or the largest of two or more arguments. |
memoryview() | Returns a memory view object. |
min() | Returns the smallest item in an iterable or the smallest of two or more arguments. |
next() | Retrieves the next item from an iterator. |
object() | Returns a new featureless object. |
oct() | Converts an integer to an octal string. |
open() | Opens a file and returns a corresponding file object. |
ord() | Converts a character to its Unicode code. |
print() | Prints to the standard output device. |
property() | Returns a property attribute. |
range() | Returns a sequence of numbers. |
reversed() | Returns a reversed iterator. |
round() | Rounds a number to a specified number of digits. |
set() | Creates a set. |
setattr() | Sets the value of the specified attribute of an object. |
slice() | Returns a slice object. |
staticmethod() | Converts a method into a static method. |
str() | Returns a string version of an object. |
sum() | Sums the items of an iterable. |
super() | Returns a proxy object that delegates method calls to a parent or sibling class. |
tuple() | Creates a tuple. |
type() | Returns the type of an object. |
vars() | Returns the dict attribute of an object. |
zip() | Returns an iterator of tuples. |
import() | Invoked by the import statement. |
Python math Module Functions
Python provides a variety of mathematical functions through the math
module. These functions make it easy to perform common mathematical operations. Below is a list of some commonly used math functions, along with their descriptions and links to detailed guides for each function.
Function | Description |
---|---|
acosh() | Returns the inverse hyperbolic cosine of a number. |
asin() | Returns the inverse sine of a number. |
atan() | Returns the inverse tangent of a number. |
atan2() | Returns the inverse tangent of y/x in radians. |
atanh() | Returns the inverse hyperbolic tangent of a number. |
ceil() | Rounds a number up to the nearest integer. |
comb() | Returns the number of ways to choose k items from n items without repetition and without order. |
copysign() | Returns a float consisting of the value of the first parameter and the sign of the second parameter. |
cos() | Returns the cosine of a number. |
cosh() | Returns the hyperbolic cosine of a number. |
degrees() | Converts an angle from radians to degrees. |
dist() | Returns the Euclidean distance between two points (p and q), where p and q are the coordinates of that point. |
erf() | Returns the error function of a number. |
exp() | Returns e raised to the power of a number. |
fabs() | Returns the absolute value of a number. |
factorial() | Returns the factorial of a number. |
floor() | Rounds a number down to the nearest integer. |
fmod() | Returns the remainder of dividing the first number by the second number. |
frexp() | Returns the mantissa and exponent of a number as a pair (m, e). |
fsum() | Returns the sum of all items in an iterable (accurately). |
gamma() | Returns the Gamma function at x. |
hypot() | Returns the Euclidean norm. |
isclose() | Checks whether two values are close to each other. |
isfinite() | Checks whether a number is finite. |
isinf() | Checks whether a number is infinite. |
isnan() | Checks whether a value is NaN (not a number). |
isqrt() | Returns the integer square root of a number. |
lcm() | Returns the least common multiple of two integers. |
ldexp() | Returns the result of x * (2**i). |
lgamma() | Returns the natural logarithm of the absolute value of the Gamma function at x. |
log() | Returns the natural logarithm of a number, or the logarithm of a number to a specified base. |
log10() | Returns the base-10 logarithm of a number. |
log1p() | Returns the natural logarithm of 1+x. |
log2() | Returns the base-2 logarithm of a number. |
modf() | Returns the fractional and integer parts of a number. |
perm() | Returns the number of ways to choose k items from n items with order and without repetition. |
pow() | Returns the value of x raised to the power of y. |
prod() | Returns the product of all the elements in an iterable. |
radians() | Converts a degree value to radians. |
remainder() | Returns the IEEE 754-style remainder of x with respect to y. |
sin() | Returns the sine of a number. |
sinh() | Returns the hyperbolic sine of a number. |
sqrt() | Returns the square root of a number. |
tan() | Returns the tangent of a number. |
tanh() | Returns the hyperbolic tangent of a number. |
trunc() | Returns the truncated integer parts of a number. |
Python os Module Functions
The os
module in Python provides a way to interact with the operating system. It allows you to perform tasks such as navigating the file system, managing files and directories, and executing system commands. Below is a list of some commonly used functions in the os
module, along with their descriptions and links to detailed guides for each function.
Function | Description |
---|---|
listdir() | Returns a list of the names of the entries in the directory. |
mkdir() | Creates a new directory. |
makedirs() | Creates a directory and all intermediate directories. |
remove() | Deletes a file. |
rmdir() | Deletes a directory. |
removedirs() | Deletes a directory and all empty intermediate directories. |
rename() | Renames a file or directory. |
replace() | Renames a file or directory, replacing the destination if it already exists. |
stat() | Performs a stat system call on the given path. |
chmod() | Changes the mode of path to the numeric mode. |
chown() | Changes the owner and group id of path. |
getcwd() | Returns the current working directory. |
chdir() | Changes the current working directory to the given path. |
path.join() | Joins one or more path components. |
path.exists() | Returns True if the path refers to an existing path or an open file descriptor. |
path.isfile() | Returns True if the path is an existing regular file. |
path.isdir() | Returns True if the path is an existing directory. |
path.getsize() | Returns the size, in bytes, of path. |
path.abspath() | Returns a normalized absolute version of the path. |
path.basename() | Returns the base name of pathname path. |
path.dirname() | Returns the directory name of pathname path. |
path.splitext() | Splits the pathname path into a pair (root, ext). |
path.expanduser() | Expands ~ or ~user in the given path to the user’s home directory. |
walk() | Generates the file names in a directory tree. |
system() | Executes the command in a subshell. |
popen() | Opens a pipe to or from command. |
environ | A mapping object representing the string environment. |
urandom() | Returns a string of n random bytes suitable for cryptographic use. |
access() | Uses the real uid/gid to test for access to path. |
dup() | Duplicates a file descriptor. |
dup2() | Duplicates file descriptor fd to fd2. |
fsync() | Forces a write of everything to disk. |
getpid() | Returns the current process id. |
getppid() | Returns the parent process id. |
getenv() | Returns the value of the environment variable key if it exists, or default if it doesn’t. |
putenv() | Sets the environment variable named key to the string value. |
setsid() | Creates a new session and sets the process group id. |
Python random
Module Functions
The random
module in Python provides various functions to generate random numbers and perform random operations. These functions are useful for tasks such as simulations, games, and testing. Below is a list of some commonly used functions in the random
module, along with their descriptions and links to detailed guides for each function.
Function | Description |
---|---|
seed() | Initializes the random number generator. |
getstate() | Returns an object capturing the current internal state of the generator. |
setstate() | Restores the internal state of the generator from an object returned by getstate() . |
randint() | Returns a random integer between the specified values, inclusive. |
randrange() | Returns a randomly selected element from the specified range. |
choice() | Returns a randomly selected element from a non-empty sequence. |
choices() | Returns a list of randomly selected elements from a population, with optional weights. |
shuffle() | Shuffles the sequence in place. |
uniform() | Returns a random floating-point number between the specified values. |
triangular() | Returns a random floating-point number between the specified values, with a specified mode between them. |
betavariate() | Returns a random float based on the Beta distribution. |
gammavariate() | Returns a random float based on the Gamma distribution. |
lognormvariate() | Returns a random float based on a log-normal distribution. |
normalvariate() | Returns a random float based on the normal (Gaussian) distribution. |
vonmisesvariate() | Returns a random float based on the von Mises distribution. |
paretovariate() | Returns a random float based on the Pareto distribution. |
weibullvariate() | Returns a random float based on the Weibull distribution. |
Python datetime
Module Functions
The datetime
module in Python provides various functions to work with dates and times. These functions are useful for creating, manipulating, and formatting date and time objects. Below is a list of some commonly used functions in the datetime
module, along with their descriptions and links to detailed guides for each function.
Function | Description |
---|---|
datetime.now() | Returns the current local date and time. |
datetime.today() | Returns the current local date and time, with the time component set to 00:00. |
datetime.utcnow() | Returns the current UTC date and time. |
datetime.fromtimestamp() | Converts a timestamp to a datetime object. |
datetime.strptime() | Parses a string representing a date and time according to a format. |
date.today() | Returns the current local date. |
date.fromtimestamp() | Converts a timestamp to a date object. |
timedelta() | Represents a duration, the difference between two dates or times. |
datetime.combine() | Combines a date and a time to create a datetime object. |
datetime.replace() | Returns a datetime with the specified components replaced. |
datetime.astimezone() | Converts the datetime to another timezone. |
Python time
Module Functions
The time
module in Python provides various functions to work with time-related tasks. These functions are useful for measuring time, pausing execution, and formatting dates and times. Below is a list of some commonly used functions in the time
module, along with their descriptions and links to detailed guides for each function.
Function | Description |
---|---|
time() | Returns the current time in seconds since the epoch. |
sleep() | Suspends execution for the given number of seconds. |
ctime() | Converts a time expressed in seconds since the epoch to a string representing local time. |
gmtime() | Converts a time expressed in seconds since the epoch to a struct_time in UTC. |
localtime() | Converts a time expressed in seconds since the epoch to a struct_time in local time. |
mktime() | Converts a struct_time representing local time to seconds since the epoch. |
strftime() | Formats a struct_time or tuple to a string according to a format specification. |
strptime() | Parses a string representing a time according to a format specification to a struct_time . |
perf_counter() | Returns the value (in fractional seconds) of a performance counter, used for measuring time intervals. |
monotonic() | Returns the value (in fractional seconds) of a monotonic clock, which cannot go backward. |
process_time() | Returns the sum of the system and user CPU time of the current process. |
time_ns() | Returns the current time in nanoseconds since the epoch. |
Python calendar
Module Functions
The calendar
module in Python provides various functions to work with dates and calendars. These functions are useful for generating calendars, checking leap years, and other date-related tasks. Below is a list of some commonly used functions in the calendar
module, along with their descriptions and links to detailed guides for each function.
Function | Description |
---|---|
calendar() | Returns a multi-line string with a calendar for the whole year. |
month() | Returns a multi-line string with a calendar for a month. |
isleap() | Returns True if the year is a leap year, otherwise False. |
leapdays() | Returns the number of leap years in the range of years provided. |
weekday() | Returns the day of the week (0 is Monday, 6 is Sunday) for a given date. |
monthrange() | Returns a tuple with the first weekday of the month and the number of days in the month. |
monthcalendar() | Returns a matrix representing a month’s calendar. |
prcal() | Prints the calendar for an entire year. |
prmonth() | Prints the calendar for a month. |
setfirstweekday() | Sets the first day of the week (0 is Monday, 6 is Sunday). |
Python re Module Functions
The re
module in Python provides support for working with regular expressions. Regular expressions are used to match patterns in text. Below is a list of some commonly used functions in the re
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python re Module Tutorial.
Function | Description |
---|---|
re.compile() | Compiles a regular expression pattern into a regex object. This object can be used for matching using its match(), search(), and other methods. |
re.search() | Searches the entire string for the first location where the pattern matches and returns a match object. |
re.match() | Checks for a match only at the beginning of the string and returns a match object if found. |
re.fullmatch() | Checks if the entire string matches the pattern and returns a match object if it does. |
re.split() | Splits the string by occurrences of the pattern and returns a list of substrings. |
re.findall() | Finds all occurrences of the pattern in the string and returns them as a list. |
re.finditer() | Finds all occurrences of the pattern in the string and returns an iterator yielding match objects. |
re.sub() | Replaces the occurrences of the pattern in the string with the specified replacement and returns the new string. |
re.subn() | Similar to re.sub(), but also returns the number of substitutions made. |
re.escape() | Escapes all non-alphanumeric characters in the string, so they can be used in a regular expression. |
re.purge() | Clears the regular expression cache, which stores compiled patterns. |
Python json Module Functions
The json
module in Python provides a way to encode and decode data in JSON (JavaScript Object Notation) format. This is useful for data interchange between different systems. Below is a list of some commonly used functions and classes in the json
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python json Module Tutorial.
Function | Description |
---|---|
json.dump() | Serializes a Python object and writes it to a file in JSON format. |
json.load() | Deserializes JSON data from a file to a Python object. |
json.loads() | Deserializes JSON data from a string to a Python object. |
json.JSONDecoder | A class used for decoding JSON data into Python objects. |
json.JSONEncoder | A class used for encoding Python objects into JSON data. |
Python sys Module Functions
The sys
module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows you to interact with the interpreter and perform tasks such as accessing command-line arguments, handling standard input and output, and managing the recursion limit. Below is a list of some commonly used functions and attributes in the sys
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python sys Module Tutorial.
Function | Description |
---|---|
argv | A list of command-line arguments passed to the script. |
exit() | Exits from Python. |
path | A list of strings that specifies the search path for modules. |
modules | A dictionary mapping module names to modules which have already been loaded. |
version | A string containing the version number of the Python interpreter. |
platform | A string identifying the platform on which Python is running. |
getsizeof() | Returns the size of an object in bytes. |
setrecursionlimit() | Sets the maximum depth of the Python interpreter stack. |
getrecursionlimit() | Returns the current value of the recursion limit. |
getdefaultencoding() | Returns the current default string encoding used by the Unicode implementation. |
stdin | A file object representing the standard input stream. |
stdout | A file object representing the standard output stream. |
stderr | A file object representing the standard error stream. |
executable | A string representing the executable binary for the Python interpreter. |
Python collections Module Functions
The collections
module in Python provides alternatives to Python’s general-purpose built-in containers like dict, list, set, and tuple. These alternatives are useful for specific needs and can make your code more readable and efficient. Below is a list of some commonly used functions and classes in the collections
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python collections Module Tutorial.
Function/Class | Description |
---|---|
collections.namedtuple() | Factory function for creating tuple subclasses with named fields. |
collections.deque | A double-ended queue that allows appending and popping from both ends. |
collections.ChainMap | Groups multiple dictionaries into a single view for easy lookup. |
collections.Counter | A dictionary subclass for counting hashable objects. |
collections.OrderedDict | A dictionary subclass that remembers the order entries were added. |
collections.defaultdict | A dictionary subclass that calls a factory function to supply missing values. |
collections.UserDict | A wrapper around dictionary objects for easier subclassing. |
collections.UserList | A wrapper around list objects for easier subclassing. |
collections.UserString | A wrapper around string objects for easier subclassing. |
Python itertools Module Functions
The itertools
module in Python provides a collection of tools for handling iterators. These functions are fast and memory-efficient and can be used to perform various operations on iterators. Below is a list of some commonly used functions in the itertools
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python itertools Module Tutorial.
Function | Description |
---|---|
itertools.count() | Creates an iterator that returns evenly spaced values starting from a given number. |
itertools.cycle() | Creates an iterator that cycles through the elements of an iterable indefinitely. |
itertools.repeat() | Creates an iterator that returns a specified value repeatedly. |
itertools.accumulate() | Creates an iterator that returns accumulated sums or the results of a specified function. |
itertools.chain() | Creates an iterator that returns elements from multiple iterables, one after another. |
itertools.compress() | Filters elements from an iterable, returning only those that have a corresponding element in a selector iterable that evaluates to True. |
itertools.filterfalse() | Filters elements from an iterable, returning only those for which the predicate is False. |
itertools.groupby() | Creates an iterator that returns consecutive keys and groups from the iterable. |
itertools.islice() | Creates an iterator that returns selected elements from the iterable, similar to slicing. |
itertools.starmap() | Creates an iterator that applies a function to the elements of an iterable, similar to map(), but the elements are unpacked. |
itertools.takewhile() | Creates an iterator that returns elements from the iterable as long as the predicate is True. |
itertools.tee() | Creates multiple independent iterators from a single iterable. |
itertools.permutations() | Creates an iterator that returns all possible permutations of elements in the iterable. |
itertools.combinations() | Creates an iterator that returns all possible combinations of elements in the iterable. |
itertools.product() | Creates an iterator that returns the Cartesian product of input iterables. |
itertools.pairwise() | Creates an iterator that returns consecutive pairs of elements from the iterable. |
Python functools Module Functions
The functools
module in Python provides higher-order functions and operations on callable objects. These functions can be used to extend the capabilities of other functions and improve the efficiency of your code. Below is a list of some commonly used functions in the functools
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python functools Module Tutorial.
Function | Description |
---|---|
functools.cache() | Decorator to cache function results to speed up repeated calls with the same arguments. |
functools.cached_property() | Converts a method into a property whose value is computed once and then cached as a normal attribute for the life of the instance. |
functools.cmp_to_key() | Converts an old-style comparison function to a key function. |
functools.lru_cache() | Decorator that caches the results of a function using a Least Recently Used (LRU) algorithm. |
functools.partial() | Creates a new function with partial application of the given arguments and keywords. |
functools.partialmethod() | Like partial() , but for methods in a class. |
functools.singledispatch() | Transforms a function into a single-dispatch generic function. |
functools.reduce() | Applies a binary function cumulatively to the items of a sequence, reducing it to a single value. |
functools.update_wrapper() | Updates a wrapper function to look more like the wrapped function by copying attributes such as the docstring. |
functools.wraps() | Decorator to update the wrapper function to look more like the wrapped function. |
Python threading Module Functions
The threading
module in Python provides a way to create and manage threads, allowing for concurrent execution of code. This can be useful for improving the performance of programs that perform multiple tasks simultaneously. Below is a list of some commonly used functions and classes in the threading
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python threading Module Tutorial.
Function/Class | Description |
---|---|
threading.Thread | A class for creating and managing individual threads. |
threading.Lock | A class for creating a lock object, used to ensure that only one thread accesses a resource at a time. |
threading.RLock | A reentrant lock that allows a thread to acquire the same lock multiple times. |
threading.Condition | A class for condition variables, which allow threads to wait for some condition to be met. |
threading.Event | A class for event objects, which allow threads to wait for an event to be set. |
threading.Semaphore | A class for semaphore objects, used to control access to a resource by a set number of threads. |
threading.BoundedSemaphore | A bounded semaphore that prevents the semaphore’s value from going above a specified maximum. |
threading.Timer | A class for creating a timer that runs a function after a specified interval. |
threading.Barrier | A class for creating a barrier that blocks threads until a specified number of threads have reached it. |
threading.local | A class for creating thread-local data, which is data that is unique to each thread. |
threading.active_count() | Returns the number of currently active threads. |
threading.current_thread() | Returns the current thread object. |
threading.enumerate() | Returns a list of all currently active thread objects. |
threading.main_thread() | Returns the main thread object. |
threading.get_ident() | Returns the current thread’s identifier. |
threading.get_native_id() | Returns the native integral thread ID of the current thread. |
threading.settrace() | Sets a trace function for all threads started from the threading module. |
threading.setprofile() | Sets a profile function for all threads started from the threading module. |
threading.stack_size() | Returns the size of the thread stack used when creating new threads. |
Python enum Module Functions
The enum
module in Python provides a way to define enumerations, which are a set of symbolic names bound to unique, constant values. Enumerations can help make code more readable and maintainable. Below is a list of some commonly used classes and functions in the enum
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python enum Module Tutorial.
Function/Class | Description |
---|---|
enum.Enum | Base class for creating enumerations. Members are accessed as ClassName.member . |
enum.IntEnum | Base class for creating enumerations, where members are also (and must be) integers. |
enum.StrEnum | Base class for creating enumerations, where members are also (and must be) strings. |
enum.Flag | Base class for creating flag enumerations, which can be combined using bitwise operations. |
enum.auto() | Used to automatically assign values to members in an enumeration. |
enum.unique() | A class decorator that ensures all enumeration values are unique. |
Python cmath Module Functions
The cmath
module in Python provides functions for complex number mathematics. These functions are useful for performing mathematical operations on complex numbers. Below is a list of some commonly used functions in the cmath
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python cmath Module Tutorial.
Function | Description |
---|---|
cmath.acos() | Returns the arc cosine of a complex number. |
cmath.asin() | Returns the arc sine of a complex number. |
cmath.atan() | Returns the arc tangent of a complex number. |
cmath.cos() | Returns the cosine of a complex number. |
cmath.tan() | Returns the tangent of a complex number. |
cmath.acosh() | Returns the inverse hyperbolic cosine of a complex number. |
cmath.asinh() | Returns the inverse hyperbolic sine of a complex number. |
cmath.atanh() | Returns the inverse hyperbolic tangent of a complex number. |
cmath.cosh() | Returns the hyperbolic cosine of a complex number. |
cmath.sinh() | Returns the hyperbolic sine of a complex number. |
cmath.tanh() | Returns the hyperbolic tangent of a complex number. |
cmath.exp() | Returns the exponential of a complex number. |
cmath.log() | Returns the natural logarithm of a complex number. |
cmath.log10() | Returns the base-10 logarithm of a complex number. |
cmath.sqrt() | Returns the square root of a complex number. |
cmath.phase() | Returns the phase of a complex number. |
cmath.rect() | Converts polar coordinates to a complex number. |
cmath.isfinite() | Checks if a complex number is finite. |
cmath.isinf() | Checks if a complex number is infinite. |
Python operator Module Functions
The operator
module in Python provides a set of efficient functions corresponding to the intrinsic operators of Python. These functions are useful for simplifying and improving the readability of your code, especially when working with higher-order functions such as map()
, filter()
, and reduce()
. Below is a list of some commonly used functions in the operator
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python operator Module Tutorial.
Function | Description |
---|---|
operator.add() | Returns the sum of two numbers. |
operator.concat() | Concatenates two sequences. |
operator.contains() | Checks if an element is present in a container. |
operator.truediv() | Performs true division of two numbers. |
operator.floordiv() | Performs floor division of two numbers. |
operator.and_() | Performs bitwise AND operation. |
operator.xor() | Performs bitwise XOR operation. |
operator.invert() | Performs bitwise inversion. |
operator.or_() | Performs bitwise OR operation. |
operator.pow() | Returns the result of raising the first number to the power of the second number. |
operator.is_() | Checks if two objects are the same. |
operator.is_not() | Checks if two objects are not the same. |
operator.setitem() | Sets the value of an item in a container. |
operator.delitem() | Deletes an item from a container. |
operator.getitem() | Gets the value of an item in a container. |
operator.lshift() | Performs bitwise left shift operation. |
operator.mod() | Returns the remainder of division of two numbers. |
operator.mul() | Returns the product of two numbers. |
operator.neg() | Returns the negation of a number. |
operator.not_() | Returns the logical negation of a value. |
operator.pos() | Returns the value unchanged. |
operator.rshift() | Performs bitwise right shift operation. |
operator.iadd() | Performs in-place addition. |
operator.isub() | Performs in-place subtraction. |
operator.imul() | Performs in-place multiplication. |
operator.itruediv() | Performs in-place true division. |
operator.ifloordiv() | Performs in-place floor division. |
operator.imod() | Performs in-place modulus operation. |
operator.ipow() | Performs in-place exponentiation. |
operator.ilshift() | Performs in-place bitwise left shift. |
operator.irshift() | Performs in-place bitwise right shift. |
operator.iand() | Performs in-place bitwise AND operation. |
operator.ior() | Performs in-place bitwise OR operation. |
operator.ixor() | Performs in-place bitwise XOR operation. |
operator.abs() | Returns the absolute value of a number. |
operator.index() | Returns the integer value of an object. |
operator.attrgetter() | Returns a callable that fetches the given attribute from an object. |
operator.itemgetter() | Returns a callable that fetches the given item from an object. |
operator.methodcaller() | Returns a callable that calls the given method on an object. |
operator.countOf() | Returns the count of the number of times an element appears in a container. |
operator.indexOf() | Returns the index of the first occurrence of an element in a container. |
operator.truth() | Returns the truth value of an object. |
operator.lt() | Returns True if the first argument is less than the second. |
operator.le() | Returns True if the first argument is less than or equal to the second. |
operator.eq() | Returns True if the first argument is equal to the second. |
operator.ne() | Returns True if the first argument is not equal to the second. |
operator.ge() | Returns True if the first argument is greater than or equal to the second. |
operator.gt() | Returns True if the first argument is greater than the second. |
Python requests Module Functions
The requests
module in Python is a powerful and easy-to-use library for making HTTP requests. It simplifies the process of sending HTTP requests and handling responses, making it a popular choice for web scraping, API interactions, and more. Below is a list of some commonly used functions and classes in the requests
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python requests Module Tutorial.
Function/Class | Description |
---|---|
requests.request() | Constructs and sends a generic HTTP request. |
requests.get() | Sends a GET request to retrieve data from a specified URL. |
requests.post() | Sends a POST request to submit data to a specified URL. |
requests.put() | Sends a PUT request to update data at a specified URL. |
requests.delete() | Sends a DELETE request to remove data from a specified URL. |
requests.head() | Sends a HEAD request to retrieve HTTP headers from a specified URL. |
requests.options() | Sends an OPTIONS request to determine the HTTP methods supported by a specified URL. |
requests.patch() | Sends a PATCH request to partially update data at a specified URL. |
requests.Session | A class for managing and persisting settings across multiple requests, including cookies. |
Python base64 Module Functions
The base64
module in Python provides functions for encoding and decoding data using the Base64 encoding scheme. This encoding is used to represent binary data in an ASCII string format. It is commonly used in various applications, including email via MIME and storing complex data in XML or JSON. Below is a list of some commonly used functions in the base64
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python base64 Module Tutorial.
Function | Description |
---|---|
base64.b64encode() | Encodes bytes-like object using Base64 and returns the encoded bytes. |
base64.b64decode() | Decodes a Base64 encoded bytes-like object or ASCII string and returns the decoded bytes. |
base64.standard_b64encode() | Encodes bytes-like object using the standard Base64 alphabet and returns the encoded bytes. |
base64.standard_b64decode() | Decodes a standard Base64 encoded bytes-like object or ASCII string and returns the decoded bytes. |
base64.urlsafe_b64encode() | Encodes bytes-like object using the URL-safe Base64 alphabet and returns the encoded bytes. |
base64.urlsafe_b64decode() | Decodes a URL-safe Base64 encoded bytes-like object or ASCII string and returns the decoded bytes. |
Python statistics Module Functions
The statistics
module in Python provides functions for calculating mathematical statistics of numeric data. These functions are useful for analyzing data and performing statistical calculations with ease. Below is a list of some commonly used functions in the statistics
module, along with their descriptions and links to detailed guides for each function.
For a complete tutorial, visit Python statistics Module Tutorial.
Function | Description |
---|---|
statistics.mean() | Calculates the arithmetic mean (average) of the given data. |
statistics.median() | Calculates the median (middle value) of the given data. |
statistics.median_low() | Calculates the low median of the given data. |
statistics.median_high() | Calculates the high median of the given data. |
statistics.median_grouped() | Calculates the median of grouped continuous data. |
statistics.mode() | Calculates the mode (most common value) of the given data. |
statistics.multimode() | Calculates a list of the most common values in the given data. |
statistics.harmonic_mean() | Calculates the harmonic mean of the given data. |
statistics.geometric_mean() | Calculates the geometric mean of the given data. |
statistics.stdev() | Calculates the standard deviation of the given data. |
statistics.variance() | Calculates the variance of the given data. |
statistics.pstdev() | Calculates the population standard deviation of the given data. |
statistics.pvariance() | Calculates the population variance of the given data. |
statistics.quantiles() | Divides the given data into intervals based on quantiles. |
statistics.fmean() | Calculates the mean of the given data using floating-point arithmetic. |