python store string to array not characters
This question already has an answer here:
a.extend(b)
is for extending list a
by concatenating another sequence b
onto it. When b
is a string, and you force it to be interpreted as a sequence, it is interpreted as a sequence of individual characters. A simple example of this is:
>>> b = 'Hello'
>>> list(b)
['H', 'e', 'l', 'l', 'o']
Instead, you clearly want to do a.append(b)
, ie insert the entire string b
as a single new item at the end of a
.
上一篇: 将一个字符串添加到Python列表中
下一篇: python存储字符串数组不是字符