Skip to main content
Anime study buddy

Learning outcomes

By the end of this chapter, you should be able to:
  • use assignment and augmented assignment operators
  • distinguish identity and equality
  • use membership operators with strings/lists
  • apply bitwise operators at basic level

Assignment operators

x = 10
x += 5   # x = x + 5
x *= 2
print(x)
Common forms: +=, -=, *=, /=, //=, %=

Identity operators

is, is not
a = [1, 2]
b = [1, 2]
print(a == b)  # True (same value)
print(a is b)  # False (different objects)

Membership operators

in, not in
text = "python"
print("py" in text)
print("z" not in text)

Bitwise operators (intro)

&, |, ^, ~, <<, >>
a = 5   # 0101
b = 3   # 0011
print(a & b)  # 1
print(a | b)  # 7

Conditional expression (ternary)

age = 20
status = "Adult" if age >= 18 else "Minor"
print(status)

Exam-focused points

  • == checks value equality
  • is checks object identity
  • membership is very common in string/list questions
  • know at least one solved bitwise example

Practice questions

  1. Show output:
x = 8
x >>= 1
print(x)
  1. Write program to check if a character is a vowel using in.
  2. Demonstrate difference between == and is with list example.