Operators
- — Subtraction and set difference
For built-in numbers subtracts the right operand from the left. For sets and frozensets it selects elements present in the left but absent from the right; the result has the left set type for mixed built-in set operands. Ordinary sequences do not support subtraction. __sub__ and __rsub__ provide custom dispatch, including reflected fallback. Binary subtraction associates left to right and differs from unary negation.
Formal Syntax & Structure
python syntaxpython
left - rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | number, set or supporting object | Number or set from which to subtract. |
| right | number, set or supporting object | Number to subtract or set of elements to exclude. |
Return Value
object
Result selected by the operand types and their operation implementations.
Working Example
Example Snippetpython
print(20 - 7)print(2 - 4.5)print(sorted({1, 2, 3} - {2, 4}))