0Pricing
Swift Academy · Lesson

Basic String Interpolation

Embed values directly inside string literals.

What Is String Interpolation

String interpolation builds a string by embedding values directly inside a string literal. You write a backslash followed by the value in parentheses, and Swift inserts its textual form.

let name = "Alice"
let greeting = "Hello, \(name)!"
print(greeting)

Embedding a Number

Any value, not just strings, can be interpolated. Swift converts it to text automatically.

let age = 30
print("You are \(age) years old.")

All lessons in this course

  1. Basic String Interpolation
  2. Formatting Numbers in Strings
  3. Multiline String Literals
  4. Custom String Interpolation
← Back to Swift Academy