while (0 > ship_row_1_1 or ship_row_1_1 > 9) or (0 > ship_row_1_2 or ship_row_1_2 > 9)\n
or(0 > ship_col_1_1 or ship_col_1_1 > 9) or (0 > ship_col_1_2 or ship_col_1_2 > 9):
我正在使用 python 2.7.6 并遇到了一个我不确定的错误。这行太长了,我不得不侧滚动以查看结尾,所以我尝试添加“\n”,我认为这会让我在下一行继续代码。问题是我收到错误: “您的程序中有一个错误:行继续字符后出现意外字符”
'\n' 后没有空格或任何其他内容,所以我不确定为什么会收到此错误。
我是初学者,所以感谢任何帮助,并提前致谢
最佳答案
您只需添加 \
而不是 \n
如下:
简单例子
def say_hi():
while True\
and 1==1\
and 2==2:
print 'hello'
您的案例
while (0 > ship_row_1_1 or ship_row_1_1 > 9) or (0 > ship_row_1_2 or ship_row_1_2 > 9)\
or(0 > ship_col_1_1 or ship_col_1_1 > 9) or (0 > ship_col_1_2 or ship_col_1_2 > 9):
关于python - Python 上的新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22786677/