Dev Helpers
← Back

Use partialmethod to create a named operation

Use partialmethod to create a named operation in Python.

Open this example in the interactive library

Source code

from functools import partialmethod
class Robot:
    def turn(self, degrees):
        return f'Turn {degrees} degrees'
    turn_left = partialmethod(turn, -90)
print(Robot().turn_left())

Sample output

Turn -90 degrees