Skip to content

← Back to Python Course Foundations

Strings and Operators (Python)

Learning Objectives

  • Perform slicing and indexing.
  • Use common string methods.
  • Apply arithmetic, logical, identity, and membership operators.

Example

text = "Programming"
print(text[0:4])
print(text[-3:])
print(text.upper())

a, b = 10, 3
print(a + b, a > b, a in [10, 20])

Dry Run

  • text[0:4] -> Prog
  • text[-3:] -> ing
  • a > b -> True

Common Mistakes

  • Wrong slice end index expectations.
  • Confusing is with == for value comparison.

Practice

  1. Count vowels in a string.
  2. Build expression evaluator for arithmetic operators.