Operator Classes

operator.methodcaller()

Build a callable that looks up a named method on its receiver and invokes it with stored arguments. The method is looked up when the resulting callable is invoked.

Formal Syntax & Structure

python syntaxpython
operator.methodcaller(method, /, *args, **kwargs)

Parameters & Attributes

NameTypeDescription
methodstrName of the method to call.
argsobjectPositional arguments forwarded to the method or constructor.
kwargsobjectKeyword arguments forwarded to the method or constructor.

Return Value

callable

The callable result described above.

Working Example

Example Snippetpython
import operatorprint(operator.methodcaller("replace","-","_")("a-b"))
Python Reference