【发布时间】:2010-09-11 22:27:28
【问题描述】:
python 中是否有将单词拆分为单个字母列表的函数?例如:
s="Word to Split"
得到
wordlist=['W','o','r','d','','t','o' ....]
【问题讨论】:
-
老线程,但值得一提的是:大多数时候你根本不需要这样做。 python字符串的字符可以直接作为列表访问,即。
s[2]是“r”,s[:4]是“Word”,len(s)是 13。您也可以遍历它们:for char in s: print char -
@domoarrigato 但由于 srting 的不同行为和可变性列表可能是这样做的理由。
-
def show_letters(word): for ch in word: print(ch) show_letters("Hello")