print "This is a very long string that doesn't fit" + \
"on a single line"
在字符串外部,反斜杠只能以这种方式出现。对于除法,需要斜线:/。
如果要在字符串中写入逐字反斜杠,请将其加倍以进行转义:"\\"
在你的代码中,你使用了两次:
print("Length between sides: " + str((length*length)*2.6) +
" \ 1.5 = " + # inside a string; treated as literal
str(((length*length)*2.6)\1.5)+ # outside a string, treated as line cont
# character, but no newline follows -> Fail
" Units")
反斜杠
\
是错误消息所指的行继续符,在它之后,只允许换行符/空白(在下一个非空白继续“中断”行之前)。在字符串外部,反斜杠只能以这种方式出现。对于除法,需要斜线:
/
。如果要在字符串中写入逐字反斜杠,请将其加倍以进行转义:
"\\"
在你的代码中,你使用了两次:
除法运算符是
/
,而不是\
。此外,反斜杠在Python字符串中有特殊的含义。用另一个反斜杠转义:
或使用原始字符串
除法运算符是
/
,而不是\
相关问题 更多 >
编程相关推荐