Comparison and Identity Operators
Compare values with ==, !=, and identity with ===.
Comparison Operators
Comparison operators ask a yes/no question and return a Bool. Swift has ==, !=, <, >, <=, and >=.
print(3 == 3)
print(5 != 2)
print(4 < 10)Equality and Inequality
== tests whether two values are equal; != tests whether they differ. These work for numbers, strings, and many other types.
let a = "swift"
let b = "Swift"
print(a == b)
print(a != b)All lessons in this course
- Arithmetic and Compound Assignment Operators
- Comparison and Identity Operators
- Logical Operators and Short-Circuiting
- Bitwise and Overflow Operators