可以使用Python中的for循环来遍历字符串中的每个字符,并将其添加到一个列表中:

string = "hello"
characters = []

for char in string:
    characters.append(char)

print(characters)  # ['h', 'e', 'l', 'l', 'o']

另外,也可以使用字符串的split()方法将其拆分为一个字符列表:

string = "hello"
characters = string.split()

print(characters)  # ['h', 'e', 'l', 'l', 'o']

需要注意的是,split()方法默认会以空格作为分隔符,如果想要拆分成单个字符,则需要指定一个空字符串作为分隔符:

string = "hello"
characters = list(string.split(""))

print(characters)  # ['h', 'e', 'l', 'l', 'o']
将字符串拆分成单个字符

原文地址: http://www.cveoy.top/t/topic/l1W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录