使用单个打印命令打印多行代码时语法无效[重复]

问题描述 投票:0回答:2

当我执行下面的代码时,解释器给我一个语法错误。我该如何解决它?

print("Day 1 - String Manipulation\nString Concatenation is done with the "+" sign.\n e.g. print("Hello " + "world")\nNew lines can be created with a backslash and n.")
python syntax-error
2个回答
0
投票

您可以通过多种方式使用打印语句。下面列出了其中一些。

print(“你好”+“ world") # 连接。注意:数据类型

打印(f“你好 世界。 {some_othervariables}") # f 字符串方式

打印(“你好 ”、“世界”)


-1
投票

第一天 - 字符串操作。 字符串连接是通过“+”号完成的。 例如打印(“你好”+“世界”)。 可以使用反斜杠和 n 创建新行。

© www.soinside.com 2019 - 2024. All rights reserved.