Inserting a string into a list without getting split into characters

后端 未结 9 1845
孤城傲影
孤城傲影 2020-12-13 16:45

I\'m new to Python and can\'t find a way to insert a string into a list without it getting split into individual characters:

>>> list=[\'hello\',\'w         


        
9条回答
  •  生来不讨喜
    2020-12-13 17:22

    To add to the end of the list:

    list.append('foo')
    

    To insert at the beginning:

    list.insert(0, 'foo')
    

提交回复
热议问题