R
Rishtaara
Python: Zero to Professional
Lesson 4 of 40Article16 min

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.

String basics
msg = "  Hello Python  "
print(msg.strip().upper())
print(msg[2:7])  # Hello

Python 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.

Boolean expressions
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.

Operators in action
x, y = 10, 4
print(x > y, x == y)
print("py" in "python")
count = 5
count += 1
print(count)