我如何分割字符串的字母?例如,我想把“Hello”变成“h l o w o l d”。我尝试使用.split方法,但它只分割单词,而不是所有字符。有什么办法我能做到吗?
发布于 2022-05-23 19:47:27
您应该使用join和生成器表达式:
strng = 'Hello World'
' '.join(i.lower() if i != ' ' else '' for i in strng)输出:
'h e l l o w o r l d'发布于 2022-05-23 19:45:57
这应该可以做到:
letters = [c for c in 'Hello World' if c != ' ']结果:
['H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd']https://stackoverflow.com/questions/72354017
复制相似问题