Strings, Booleans & Operators
Strings are text in single or double quotes. They support slicing, len(), upper(), lower(), strip(), and in.
Python Strings
Strings are text in single or double quotes. They support slicing, len(), upper(), lower(), strip(), and in.
Strings are immutable — methods return new strings.
Real-life example: A string is a necklace of letter beads — you can read a section (slice) but each bead stays in order.
msg = " Hello Python "
print(msg.strip().upper())
print(msg[2:7]) # HelloPython Booleans
bool values are True and False (capital T and F). Comparisons and logic operators produce booleans.
Empty strings, 0, None, and empty collections are falsy in if checks.
Real-life example: A boolean is a traffic light — only green (True) or red (False), no maybe.
logged_in = True
print(logged_in and True)
print(not logged_in)
print(bool(""), bool("hi"), bool(0))Python Operators
Arithmetic: + - * / // % **. Comparison: == != > < >= <=. Logical: and or not. Assignment: += -= etc.
Membership: in / not in. Identity: is / is not (compare object identity).
Real-life example: Operators are kitchen tools — + adds ingredients, == checks if two bowls hold the same amount.
x, y = 10, 4
print(x > y, x == y)
print("py" in "python")
count = 5
count += 1
print(count)