operator — Easy Examples
Standard operators as functions: itemgetter, attrgetter, add, mul
Getting started with operator
Basic import and usage of the operator module.
python
import operator # Operator functions print(operator.add(3, 4)) print(operator.mul(5, 6)) # itemgetter for sorting from operator import itemgetter data = [("Alice", 30), ("Bob", 25), ("Charlie", 35)] print(sorted(data, key=itemgetter(1)))
The operator module is part of Python's standard library. Standard operators as functions: itemgetter, attrgetter, add, mul.
Common operator operations
Frequently used functions from the operator module.
python
# More operator examples import operator print(f"operator module loaded successfully") print(f"Location: {operator.__name__}") print(f"Has {len(dir(operator))} attributes")
These are the most commonly used features of the operator module.
Want to try these examples interactively?
Open Easy Playground