我试图使用\n
将此字符串格式化为电路板,某处存在语法错误,但我不知道在哪里!
f1= ("a" "b" "c" + "|"\n + " -------------"+"\n" + "1 |",gameboard[0],"|",gameboard [ 1], "|" ,gameboard[2], "|"+"\n" + "2","|",gameboard[3],"|",gameboard[4], "|" ,gameboard[5],"|" +"\n" + "3","|",gameboard[6],"|",gameboard[7], "|" ,gameboard[8], "|"+"\n"+ "-------------")
gameboard = ['O', ' ', ' ', 'O', 'X', ' ', 'O', ' ', 'X']
print(f1)
答案 0 :(得分:4)
你已经遇到麻烦了:
f1= ("a" "b" "c" + "|"\n
不幸的是,我无法猜出你希望希望做什么。它相当于:
f1= ("abc|"\n
如果你只是将\n
单独放在一行上,你就会得到同样的错误:
>>> \n
SyntaxError: unexpected character after line continuation character
\n
在带引号的字符串之外没有任何意义。
后来:现在你添加了一张图片,这是一个开始:
print " a b c"
print " -----------"
这很简单。它只是简单的坚果;-)试图把它全部塞进一条线上。如果你觉得必须,那两张照片就相当于这张照片 - 更难阅读 - 打印:
print " a b c\n -----------"