ID EN
Functools

partialmethod

Python 3.11 🇮🇩 Bahasa Indonesia

Mengembalikan deskriptor metode parsial baru yang berperilaku seperti parsial kecuali bahwa deskriptor tersebut dirancang untuk digunakan sebagai definisi metode dan bukan dapat dipanggil secara langsung.

Syntax

PYTHON
class functools.partialmethod(func, /, *args, **keywords)

Contoh

Example 1
PYTHON
>>> class Cell:
...     def __init__(self):
...         self._alive = False
...     @property
...     def alive(self):
...         return self._alive
...     def set_state(self, state):
...         self._alive = bool(state)
...     set_alive = partialmethod(set_state, True)
...     set_dead = partialmethod(set_state, False)
...
>>> c = Cell()
>>> c.alive
False
>>> c.set_alive()
>>> c.alive
True

See Also

partialmethod partial descriptor classmethod() staticmethod() partialmethod partial object partialmethod