如何将字符串转换为列表? 假设字符串就像text =“a,b,c”.转换后,text == [‘a’,’b’,’c’]并希望text [0] ==’a’,text [1] ==’b’? 像这样: text = 'a,b,c' text = text.split(',') text[ 'a', 'b', 'c'
假设字符串就像text =“a,b,c”.转换后,text == [‘a’,’b’,’c’]并希望text [0] ==’a’,text [1] ==’b’?
像这样:>>> text = 'a,b,c' >>> text = text.split(',') >>> text [ 'a', 'b', 'c' ]
或者,如果您信任该字符串是安全的,则可以使用eval():
>>> text = 'a,b,c' >>> text = eval('[' + text + ']')