以下是我尝试过的结果,但出现了错误:
a = 1
b = 2
c = 3
d = 4
e = 5
if(1):
get = str(a) +"," #Line 1
+str(b) +"," #Line 2
+str(c) +"," #Line 3
+str(d) +"," #Line 4
+str(e) #Line 5
else:
get = ",,,,,"
print(get)
错误:
File "testingpython.py", line 8
+str(b) +"," #Line 2
^
IndentationError: unexpected indent
然后我尝试删除空格:
a = 1
b = 2
c = 3
d = 4
e = 5
if(1):
get = str(a) +"," #Line 1
+str(b) +"," #Line 2
+str(c) +"," #Line 3
+str(d) +"," #Line 4
+str(e) #Line 5
else:
get = ",,,,,"
print(get)
错误:
File "testingpython.py", line 12
else:
^
SyntaxError: invalid syntax
请让我知道,当字符串值放在单独的行上时,如何将它们赋给变量。你知道吗
最简单的解决方案是将行包装在parethesis中,以表明它们属于一起:
但你可以用一个较短的方法:
在Python中,我们通常使用
\
符号将一条语句分成多行iff语句不在括号内,如下所示:可以说:
或者,如果语句带有括号,则不需要
\
作为:相关问题 更多 >
编程相关推荐