String Interpolation in Swift

Level 143 keystrokes

Embeds the value of the constant name in a string with \() and prints "Hello, Swift!".

Swift code

// let declares a constant; its type String is inferred
1let name = "Swift"
// \(name) is replaced by the value of name: Hello, Swift!
2print("Hello, \(name)!")

Output

Hello, Swift!
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Swift code and how often they appear.

  • "× 4
  • (× 2
  • )× 2
  • ,× 1
  • !× 1
  • \× 1
  • =× 1

More Swift examples at level 1

← Swift typing practice