Inserting a string into a list without getting split into characters

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

    ls=['hello','world']
    ls.append('python')
    ['hello', 'world', 'python']
    

    or (use insert function where you can use index position in list)

    ls.insert(0,'python')
    print(ls)
    ['python', 'hello', 'world']
    

提交回复
热议问题