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

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.

主站蜘蛛池模板: 修文县| 松阳县| 吴旗县| 甘孜| 辽宁省| 奉节县| 临潭县| 视频| 英超| 遂宁市| 永善县| 富源县| 文安县| 稷山县| 历史| 五家渠市| 涟水县| 镇巴县| 定南县| 临沧市| 库尔勒市| 南通市| 明光市| 吴旗县| 阿克苏市| 宜都市| 太仓市| 临漳县| 肥西县| 海原县| 睢宁县| 故城县| 柘城县| 天峻县| 监利县| 凌源市| 平潭县| 襄城县| 海城市| 桂阳县| 梅州市|