意外的EOL有两行代码

时间:2018-02-14 23:47:58

标签: python python-3.x

这是代码:

rlist=["ё","й","ц","у","к","е","н","г","ш","щ","з","х",'ъ","ф","ы","в","а',"п','р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю","Ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы",'В","А","П","Р","О","Л","Д','Ж","Э","Я","Ч","С','М","И","Т","Ь","Б","Ю"]

print(rlist)

这是错误:

Traceback (most recent call last):
  File "python", line 1
    rlist=["ё","й","ц","у","к","е","н","г","ш","щ","з","х",'ъ","ф","ы","в","а',"п','р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю","Ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы",'В","А","П","Р","О","Л","Д','Ж","Э","Я","Ч","С','М","И","Т","Ь","Б","Ю"]
                                                                                                                                                                                                                                                                                  ^
SyntaxError: EOL while scanning string literal

我正在使用在线翻译,所以如果这不能编译在你身边,我很抱歉

1 个答案:

答案 0 :(得分:3)

问题是某些字符的引号不一致。

一个例子是M,左边有一个引号,右边有双引号:

'М","И","Т","Ь","Б","Ю"]

在这样的情况下,列表中的每个字符串只有一个字符长,最好像这样使用list

>>> rlist = [
...     "ё", "й", "ц", "у", "к", "е", "н", "г", "ш", "щ", "з", "х", "ъ", "ф", "ы",
...     "в", "а", "п", "р", "о", "л", "д", "ж", "э", "я", "ч", "с", "м", "и", "т",
...     "ь", "б", "ю", "Ё", "Й", "Ц", "У", "К", "Е", "Н", "Г", "Ш", "Щ", "З", "Х",
...     "Ъ", "Ф", "Ы", "В", "А", "П", "Р", "О", "Л", "Д", "Ж", "Э", "Я", "Ч", "С",
...     "М", "И", "Т", "Ь", "Б", "Ю"
... ]
>>> rlist_2 = list('ёйцукенгшщзхъфывапролджэячсмитьбюЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ')
>>> rlist == rlist_2
True