There’s an even simpler way to include values in strings: Write the value in parentheses, and write a backslash (\
) before the parentheses. This is known as string interpolation.
let apples = 3
let oranges = 5
let appleSummary = "I have \(apples) apples."
let fruitSummary = "I have \(apples + oranges) pieces of fruit."
时间: 2024-09-30 15:32:17