0Pricing
Swift Academy · Lesson

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

  1. Arithmetic and Compound Assignment Operators
  2. Comparison and Identity Operators
  3. Logical Operators and Short-Circuiting
  4. Bitwise and Overflow Operators
← Back to Swift Academy