Operators

Python - A Quick Start for existing Programers

2 min read

Published Sep 16 2025, updated Sep 30 2025


21
0
0
0

Python

Arithmetic operators

Operator

Description

Example

+

Addition

5 + 3 = 8

-

Subtraction

5 - 3 = 2

*

Multiplication

5 * 3 = 15

/

Division (float result)

5 / 2 = 2.5

//

Floor division (integer result)

5 // 2 = 2

%

Modulus (remainder)

5 % 2 = 1

**

Exponentiation

5 ** 2 = 25



Comparison operators

Operator

Description

Example

==

Equal to

5 == 5 → True

!=

Not equal to

5 != 3 → True

>

Greater than

5 > 3 → True

<

Less than

5 < 3 → False

>=

Greater than or equal to

5 >= 5 → True

<=

Less than or equal to

5 <= 4 → False




Logical operators

Operator

Description

Example

and

True if both operands are True

True and False → False

or

True if at least one operand is True

True or False → True

not

Negates the boolean value

not True → False




Assignment operators

Note: there is no short hand to increment or decrement a variables value that other languages have such as i++ or i--.

Operator

Description

Example

=

Assign

x = 5

+=

Add and assign

x += 3 → x = x + 3

-=

Subtract and assign

x -= 3 → x = x - 3

*=

Multiply and assign

x *= 3 → x = x * 3

/=

Divide and assign

x /= 3 → x = x / 3

//=

Floor divide and assign

x //= 3 → x = x // 3

%=

Modulus and assign

x %= 3 → x = x % 3

**=

Exponentiate and assign

x **= 3 → x = x ** 3




Identity operators

Operator

Description

Example

is

True if both refer to the same object

x is y

is not

True if they refer to different objects

x is not y




Membership operators

Operator

Description

Example

in

True if value exists in a sequence

'a' in 'cat' → True

not in

True if value does not exist in a sequence

'z' not in 'cat' → True




Bitwise operators

Operator

Description

Example

&

AND

5 & 3 → 1

|

OR

5 | 3 → 7

^

XOR

5 ^ 3 → 6

~

NOT

~5 → -6

<<

Left shift

5 << 1 → 10

>>

Right shift

5 >> 1 → 2

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact