# Operators and Operands in Python

Python assignment operators:

numExample = 2

numExample += 2

print(numExample)

numExample -= 1

print(numExample)

numExample **= 2

print(numExample)

numExample *= 4

print(numExample)

numExample /= 2

print(numExample)

numExample %= 5

print(numExample)

numExample //= 2

print(numExample)

Output of above:

4

3

9

36

18.0

3.0

1.0

Python’s binary operators (operators with two operands):

Subtraction: –

Multiplication: *

Regular division: /

Modulus: %

Exponentiation: **

Floor division: //

Equality: ==

Not equal to: !=

Not: print(True == (not False))

Assignment: =

Greater than or equal to: >=

Greater than: >

Less than or equal to: <=

Less than: <

And: and

Or: or

Python’s lack of unary operators (operators with one operand):

Python doesn’t have unary ++ or — operators even though other languages do. However, you can use binary assignment operators instead, like so:

x = 5

x += 1

y = 3

y -= 1

Alternatively, you can do this:

x = x + 1

y = y – 2

Python Topic List

Main Topic List