Python-在新列表中连接非类型和字符串 问题

Python-在新列表中连接非类型和字符串 问题,python,python-3.x,Python,Python 3.x,如何在新列表中连接None和string >>> a = None >>> b = 'apple,banana,cherry' >>> new_list = a + b Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'NoneType

如何在新列表中连接None和string

>>> a = None
>>> b = 'apple,banana,cherry'
>>> new_list = a + b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
>>>
>a=None
>>>b=‘苹果、香蕉、樱桃’
>>>新列表=a+b
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:不支持+:“NoneType”和“str”的操作数类型
>>>
预期产量
>新列表=[无,'苹果,香蕉,樱桃']
>>>打印(新列表)
[无“苹果、香蕉、樱桃”]
>>>打印(类型(新列表))
>>>

要使用append方法将项目添加到列表中,请执行以下操作:

my_list = []
a = None
b = 'apple,banana,cherry'

# adds a to the list
my_list.append(a)

# adds b to the list
my_list.append(b)

new\u list=[a,b]
如果使用列表串联,则
a
b
都必须是列表:
a=[None]
b=['apple,banana,cherry']
。这两个代码都不同,因此结果也不同。使用预期的输出代码获得预期的结果。你能解释一下你的怀疑吗?@BrianRodriguez非常感谢!现在可以了!
my_list = []
a = None
b = 'apple,banana,cherry'

# adds a to the list
my_list.append(a)

# adds b to the list
my_list.append(b)