2017-09-26 129 views
1

當字符串文字跨越多行時,可以在python中使用三引號"""..."""定義一個跨越多行的字符串

>>> string = """\ 
... Usage: thingy [OPTIONS] 
...  -h      Display this usage message 
...  -H hostname    Hostname to connect to 
... """ 
>>> 

在R中是否有像這樣的可能方式?

回答

4

[R串也支持這樣的行爲:

string <- " 
    ... Usage: thingy [OPTIONS] 
    ...  -h      Display this usage message 
    ...  -H hostname    Hostname to connect to 
    ... " 

print(string) 

輸出:

[1] "\n... Usage: thingy [OPTIONS]\n...  -h   
      Display this usage message\n...  -H hostname 
      Hostname to connect to\n... " 
+2

你可能想使用'貓(串)''因爲逃逸print'輸出。 – Eumenedies

+0

@Eumenedies帶點,但這可能取決於OP計劃如何處理字符串。看到那裏的文字換行讓我們知道R已經記錄了多條線。 –