我一直在使用类似这样的东西来获取字符串并将其分解以添加到列表中
example_string = "Test"
example_list =[]
for x in example_string:
example_list.append(x)
输出:
example_list = ['T','e','s','t']
有更直接的方法吗?
请您参考如下方法:
你的意思比:
example_string = "Test"
example_list = list(example_string)
输出:
example_list = ["T","e","s","t"]
在 python 中,字符串像列表或元组一样是可迭代的,您可以通过调用 tuple() 或 list() 轻松地将字符串转换为元组或列表.
