>>> arr = [ 'asdf' 'asdfsdgf' ]
>>> print arr
['asdfasdfsdgf']
为什么存在隐式字符串连接而不是SyntaxError
?
答案 0 :(得分:6)
相邻字符串在Python中连接:
>>> "Happy " "Birthday!"
'Happy Birthday!'
>>>
这只是语法。您需要在列表中使用逗号分隔项目:
>>> arr = ["asdf", "asdfsdgf"]
>>> # --^
>>> arr
['asdf', 'asdfsdgf']
答案 1 :(得分:0)
隐式字符串连接允许您在多行上拆分长字符串以提高可读性:
list_of_strings = [ "really long line " # Start of first string
"to split for readability", # Continuation of first string
"short string 1",
"short string 2"
]
list_of_strings
包含3个元素。