奇怪的有效python语法与字符串

时间:2018-06-05 10:41:29

标签: python syntax

我在Python 3.6.1上运行,今天我错过了一个逗号,如下所示:

nt = namedtuple('Record', ['c', 'a' 'b'])
# instead the following is what I actually want
nt = namedtuple('Record', ['c', 'a', 'b'])

但我只是想知道为什么第一种方式是有效的Python?它不应该抱怨语法错误吗?

我刚试过3.5.2和2.7.11。似乎全部有效。但它有效吗?

2 个答案:

答案 0 :(得分:0)

来自Python tutorial

  

两个或多个字符串文字(即引号之间包含的字符串)   彼此相邻会自动连接。

>>> 'Py' 'thon'
'Python'

答案 1 :(得分:0)

Python将连接由空格分隔的相邻字符串: https://docs.python.org/2.0/ref/string-catenation.html