How to convert a str to a single element list in python

前端 未结 5 556
无人共我
无人共我 2020-12-29 03:08

I have a str variable: var_1 = \"hello\" , and I want to convert it to a single element list, I try this:

>>>         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 04:11

    Let me provide you a much easier and authentic way to do it.

    s='hello' L=[] L.append(s)

    You will get a list with 'hello' as its element. And you can use the list L anyway you like.

提交回复
热议问题