Unary and Binary Operators in Python

What are Unary and Binary Operators and why do we use them?

Graham Waters
Towards Data Analytics
2 min readMar 30, 2022

--

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).

Photo by Elen Yatsenko on Unsplash

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.

Photo by Mitya Ivanov on Unsplash

The Addition Operator

--

--