Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Python functools Module



The Python functools module is determined for higher-order functions, this function accepts other functions as parameters and returns the given value. These higher-order functions, often referred to as decorators.

This module specifies different utilities for working with higher-order functions and callable objects. This function includes cumulative operations, selecting partial functions, and including functions for caching.

Hence, functools is one of the most useful libraries in Python. This library offers a collection of higher-order functions.

List of functools

The table below showcases values in this module, explains and elaborates on the functions within the functools module.

S.No Function & Description
1

partial()

This function transforms multi-arguments functions into single-argument and creates a partial object with predefined arguments.

2

partialmethod()

This function creates a class method with predefined values.

3

reduce()

This function gives accumulated output values with an optional initializer.

4

wraps()

This function updates the wrapper function attributes to those of the original function.

5

lru_cache()

This decorator caches recent function for efficiency, with a default maxsize of 128.

6

cache()

This function caches unlimited values.

7

cached_property()

This function determines the class attribute in cached properties.

8

total_ordering()

This decorator automatically defines missing comparison methods if __eq__(), __gt__ and __ge__ methods.

9

singledispatch()

This decorator allows functions to behave differently based on argument types.

python_modules.htm
Advertisements