Partialmethod class
It is a method definition of an already defined function for specific arguments like a partial function. However, it is not callable but is only a method descriptor. It returns a new partialmethod descriptor.
Syntax:
partialmethod(func, *args, **keywords)
Example:
Python3
from functools import partialmethod class Demo: def __init__( self ): self .color = 'black' def _color( self , type ): self .color = type set_red = partialmethod(_color, type = 'red' ) set_blue = partialmethod(_color, type = 'blue' ) set_green = partialmethod(_color, type = 'green' ) obj = Demo() print (obj.color) obj.set_blue() print (obj.color) |
Output :
black blue
Functools module in Python
Functools module is for higher-order functions that work on other functions. It provides functions for working with other functions and callable objects to use or extend them without completely rewriting them. This module has two classes – partial and partialmethod.