如何在python中将字符串转换为列表
我的字符串为:如何在python中将字符串转换为列表,python,python-3.x,Python,Python 3.x,我的字符串为: myString = 'example' 如何将其转换为以下列表: lst = ['example'] 以有效的方式?最自然的方式是正确的: mystr = 'example' lst = [mystr] 另外,不要将变量命名为str;它覆盖内置str。您可以使用append函数来实现: lst = [] str = 'example' lst.append(str) str='example' 现在,当s='example'时,l将包含['e','x','a','m
myString = 'example'
如何将其转换为以下列表:
lst = ['example']
以有效的方式?最自然的方式是正确的:
mystr = 'example'
lst = [mystr]
另外,不要将变量命名为str;它覆盖内置str。您可以使用append函数来实现:
lst = []
str = 'example'
lst.append(str)
str='example'
现在,当s='example'时,l将包含['e','x','a','m','p','l','e']s]或s.split。虽然s.split要慢得多。可能是
l=list(str)