Swift 4编程三重引号

Swift 4编程三重引号,swift,Swift,当他们说“它与收盘报价的缩进一致”时,这是什么意思 对占用多行的字符串使用三个双引号(“”)。只要每个引号行的开头缩进与结束引号的缩进匹配,就会删除该行。例如: 让我们引用“”“ 即使左边有空格, 实际行没有缩进。 除了这条线。 双引号(“)可以在不转义的情况下出现 我还有(苹果+桔子)片水果。 """ 使用方括号([])创建数组和字典,并通过在方括号中写入索引或键来访问其元素。最后一个元素后允许使用逗号。“ 摘自:Apple Inc.“Swift编程语言(Swift 4)。”iBooks.以下

当他们说“它与收盘报价的缩进一致”时,这是什么意思

对占用多行的字符串使用三个双引号(“”)。只要每个引号行的开头缩进与结束引号的缩进匹配,就会删除该行。例如:

让我们引用“”“ 即使左边有空格, 实际行没有缩进。 除了这条线。 双引号(“)可以在不转义的情况下出现

我还有(苹果+桔子)片水果。 """ 使用方括号([])创建数组和字典,并通过在方括号中写入索引或键来访问其元素。最后一个元素后允许使用逗号。“


摘自:Apple Inc.“Swift编程语言(Swift 4)。”iBooks.

以下是我可以想到的三种情况来解释这一点:

此处文本和三重引号向左对齐

选中ouput,此处存储并打印文本,每段开头不留空格

let textSample1 = """
Test 1: Hello how are you welcome to the test
something else is written here
that's enough said
"""

print(textSample1)
此处文本开头有空格,但三个引号向左对齐

选中ouput,此处存储文本并在每个段落的开头用空格打印,因为tripe引号位于左侧,并且它们考虑了段落中的空格

let textSample2 = """
  Test 2: Hello how are you welcome to the test
  something else is written here
  that's enough said
"""

print(textSample2)
此处文本开头有空格,三个引号也有空格以匹配文本

检查ouput,这里文本的存储和打印在开头没有空格,虽然我们在开头放了空格,这是因为三重引号与文本位于同一级别,而不是空格,所以它们被忽略。我发现当你想在代码中存储多行文本,但想维护除了其他用途之外,还有一些代码格式

let textSample3 = """
    Test 3: Hello how are you welcome to the test
    something else is written here
    that's enough said
    """

print(textSample3)
输出:

Test 1: Hello how are you welcome to the test
something else is written here
that's enough said

  Test 2: Hello how are you welcome to the test
  something else is written here
  that's enough said

Test 3: Hello how are you welcome to the test
something else is written here
that's enough said

以下是我可以想到的三种情况来解释这一点:

此处文本和三重引号向左对齐

选中ouput,此处存储并打印文本,每段开头不留空格

let textSample1 = """
Test 1: Hello how are you welcome to the test
something else is written here
that's enough said
"""

print(textSample1)
此处文本开头有空格,但三个引号向左对齐

选中ouput,在这里,文本将存储并打印在每个段落的开头,因为tripe引号位于左侧,并且它们考虑到段落中的这些空格

let textSample2 = """
  Test 2: Hello how are you welcome to the test
  something else is written here
  that's enough said
"""

print(textSample2)
此处文本开头有空格,三个引号也有空格以匹配文本

检查ouput,这里文本的存储和打印在开头没有空格,虽然我们在开头放了空格,这是因为三重引号与文本位于同一级别,而不是空格,所以它们被忽略。我发现当你想在代码中存储多行文本,但想维护除了其他用途之外,还有一些代码格式

let textSample3 = """
    Test 3: Hello how are you welcome to the test
    something else is written here
    that's enough said
    """

print(textSample3)
输出:

Test 1: Hello how are you welcome to the test
something else is written here
that's enough said

  Test 2: Hello how are you welcome to the test
  something else is written here
  that's enough said

Test 3: Hello how are you welcome to the test
something else is written here
that's enough said
我强烈建议你打开Xcode游乐场,玩这些东西……你可能会惊讶于你的发现;)我强烈建议你打开Xcode游乐场,玩这些东西……你可能会惊讶于你的发现;)