Comparison Operators
== != < > <= >= compare values and return True or False; they can be chained.
Beginner
0 <= x < 10 # chained: same as 0 <= x and x < 10
"apple" < "banana" # strings compare alphabetically (by Unicode code point)
[1, 2] == [1, 2] # True — compares contents
Compare floats with math.isclose(a, b) rather than ==.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.