A unary operator is an operator which works on a single operand. Python support unary minus operator(-). When an operand is preceded by a minus sign, then the unary operator negates its value.
For example, if a number is positive, it becomes negative when the number is preceded by the unary operator.
Python Unary Operator Example
x=100 y=-(x) print(y)
Output:
-100
Here we are applying unary minus operator(-) on the operand x; the value of y becomes -100, which indicates it as a negative value.
Leave a comment