[英]Are elements separated in a list with a comma?
If I create a list in python like this:如果我在 python 中创建一个列表,如下所示:
list1 = ['a' 'b' 'c']
or或者
list2 = ['a','b','c']
What is the difference between list1
and list2
? list1
和list2
有什么区别?
The difference is that list1
's value would be ['abc']
, while list2
's value would be ['a', 'b', 'c']
.不同之处在于
list1
的值为['abc']
,而list2
的值为['a', 'b', 'c']
。
Observe:观察:
>>> ['a' 'b' 'c']
['abc']
>>> ['a', 'b', 'c']
['a', 'b', 'c']
>>>
This is due to the fact that adjacent string literals (delimited by whitespace), possibly using different quoting conventions, are allowed, and their meaning is the same as their concatenation.这是因为允许使用可能使用不同引用约定的相邻字符串文字(由空格分隔),并且它们的含义与它们的连接相同。 Thus,
"hello" 'world'
is equivalent to "helloworld"
.因此,
"hello" 'world'
等价于"helloworld"
。
The above is a quote from the documentation: String literal concatenation以上是来自文档的引用: String literal concatenation
The first example creates a list with one element, ['abc']
.第一个示例创建一个包含一个元素
['abc']
的列表。 The second creates a list with 3 elements: ['a', 'b', 'c']
.第二个创建一个包含 3 个元素的列表:
['a', 'b', 'c']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.