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

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.

主站蜘蛛池模板: 乃东县| 迁西县| 兴宁市| 若尔盖县| 都江堰市| 禹城市| 九台市| 娱乐| 云林县| 玉屏| 德阳市| 玛沁县| 毕节市| 肥西县| 清水河县| 唐海县| 通城县| 太原市| 马山县| 稷山县| 阳东县| 廊坊市| 仲巴县| 焦作市| 思南县| 黔西县| 驻马店市| 板桥市| 抚松县| 萍乡市| 巴东县| 连城县| 天峨县| 贵定县| 昌邑市| 临清市| 鸡东县| 南汇区| 沁水县| 井研县| 江源县|