官术网_书友最值得收藏!

String interpolation

To correct this, we can put these variables inside quotes, which is known as string interpolation, using a backslash and parentheses around each of our variables inside the string interpolation. Let's update our name variable to the following, and you will see the space in the name in the Results Panel:

let full = "\(firstName) \(lastName)"

After adding the preceding line, our code should look something like this:

Now that we know about using variables inside quotes, we can do the same inside print(). Let's put the firstName and lastName variables inside print(), as follows:

print("\(firstName) \(lastName)")

The print statements are great for checking to see whether you are getting the value you want:

Bam! Now, we have a way to view multiple variables inside of print() and to create string interpolation by combining multiple strings. We can do much more with Strings, and we will cover that later in this book.

主站蜘蛛池模板: 桂林市| 资中县| 沙坪坝区| 都兰县| 济阳县| 张家界市| 凉山| 稷山县| 罗定市| 甘谷县| 南和县| 内乡县| 马山县| 攀枝花市| 二连浩特市| 连州市| 芒康县| 五寨县| 成安县| 枣强县| 长垣县| 丹巴县| 惠东县| 桐乡市| 吉安市| 绥中县| 潜山县| 翁牛特旗| 定州市| 沙坪坝区| 东乡县| 武乡县| 罗江县| 岳阳市| 大安市| 青浦区| 正宁县| 乌兰县| 揭阳市| 偏关县| 隆安县|