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

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.

主站蜘蛛池模板: 二连浩特市| 满洲里市| 玛曲县| 曲周县| 通化县| 富川| 封丘县| 应用必备| 鄂伦春自治旗| 出国| 乐至县| 巴彦淖尔市| 苍南县| 开江县| 柏乡县| 商都县| 白朗县| 临汾市| 永定县| 越西县| 兴山县| 怀远县| 常德市| 内丘县| 太原市| 贵定县| 个旧市| 界首市| 克东县| 襄垣县| 武夷山市| 怀远县| 泊头市| 蒙山县| 谢通门县| 太湖县| 德庆县| 同德县| 荃湾区| 恭城| 温泉县|