Thuta Learning
BasicProgrammingbeginner

Operators

Relax. We'll talk through this in plain words — no textbook voice.

Operators are symbols used to calculate values, compare them, or check logic. In Swift, you'll use arithmetic, assignment, comparison, and logical operators pretty much every day.

swift
let price = 1200
let quantity = 3
let total = price * quantity

var wallet = 5000
wallet -= total

let canBuyAgain = wallet >= price

print("Total: \(total)")
print("Wallet left: \(wallet)")
print("Can buy again: \(canBuyAgain)")

* is multiplication, -= subtracts from the current value, and >= checks greater-than-or-equal. This kind of logic shows up a lot in shopping carts, scoring systems, and usage credit calculations.

You should see
Total: 3600 Wallet left: 1400 Can buy again: true

Easy traps

  • Writing if wallet = price inside a condition is a mistake. To compare values, use ==, >, <, >=, and so on.