Inserting a string into a list without getting split into characters

后端 未结 9 1826
孤城傲影
孤城傲影 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:24

    Sticking to the method you are using to insert it, use

    list[:0] = ['foo']
    

    http://docs.python.org/release/2.6.6/library/stdtypes.html#mutable-sequence-types

提交回复
热议问题