python store string to array not characters

This question already has an answer here:

  • Difference between append vs. extend list methods in Python 22 answers

  • 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 .

    链接地址: http://www.djcxy.com/p/22556.html

    上一篇: 将一个字符串添加到Python列表中

    下一篇: python存储字符串数组不是字符