Operators

Arithmetic, comparison, logical, bitwise operators

Interview Relevant: Essential for problem solving

Operators

Standard operators behave as expected.

Code Examples

Common operators in Python.

python
1# Arithmetic
25 + 2   # 7
35 - 2   # 3
45 * 2   # 10
55 / 2   # 2.5 (always float)
65 // 2  # 2 (floor division)
75 % 2   # 1 (modulus)
85 ** 2  # 25 (power)
9
10# Logical
11True and False  # False
12True or False   # True
13not True        # False
14
15# Comparison
165 == 5  # True
175 != 3  # True
185 > 3   # True
19
20# Identity (memory address)
21a is b      # True if same object
22a is not b
23
24# Membership
25"a" in "apple"  # True

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In