Unary and Binary Operators in Python
What are Unary and Binary Operators and why do we use them?
Python practitioners use unary and binary operators constantly and as you prepare for the PCEP exam it may be useful to know what these are.
A Unary Operator is a computational operator that takes any action on one operand and produces only one result.
For example, the “-” binary operator in Python turns the operand negative (if positive) and positive (if negative).
Example:
x=56
y=-(x)
print(y)
>>-56
A Binary Operator is a computational operator that works with two or more operands.
Initial Example
For example, “*” multiplies both of its arguments together.
There are seven binary operators that are used in Python3.