![](/img/trans.png)
[英]How do I check whether comma separated elements of a string are in the list or not?
[英]Are elements separated in a list with a comma?
如果我在 python 中创建一个列表,如下所示:
list1 = ['a' 'b' 'c']
或者
list2 = ['a','b','c']
list1
和list2
有什么区别?
不同之处在于list1
的值为['abc']
,而list2
的值为['a', 'b', 'c']
。
观察:
>>> ['a' 'b' 'c']
['abc']
>>> ['a', 'b', 'c']
['a', 'b', 'c']
>>>
这是因为允许使用可能使用不同引用约定的相邻字符串文字(由空格分隔),并且它们的含义与它们的连接相同。 因此, "hello" 'world'
等价于"helloworld"
。
以上是来自文档的引用: String literal concatenation
第一个示例创建一个包含一个元素['abc']
的列表。 第二个创建一个包含 3 个元素的列表: ['a', 'b', 'c']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.