Operators
- — Unary negation
Negates built-in numeric values, including complex numbers. It invokes __neg__ on custom types, which may return nonnumeric results. Unary minus is not the same operator as binary subtraction. In -2**2, exponentiation occurs before negation; parentheses change the base. Negative zero can be meaningful for floats even though it compares equal to positive zero.
Formal Syntax & Structure
python syntaxpython
-operandParameters & Attributes
| Name | Type | Description |
|---|---|---|
| operand | number or supporting object | Value to transform. |
Return Value
number or custom result
Numeric result for supported built-in numbers; custom methods can return other objects.
Working Example
Example Snippetpython
print(-7)print(-(-4))print(-2 ** 2, (-2) ** 2)