这是我的代码,但它不断地输出答案作为一个,而我希望它计算在句子中的字符。如何将文本与列表分开?
#-----------------------------
myList = []
characterCount = 0
#-----------------------------
Sentence = "hello world"
newSentence = Sentence.split(",")
myList.append(newSentence)
print(myList)
for character in myList:
characterCount += 1
print (characterCount)
感谢你的帮助
如果你想在句子中的字符数,为什么不使用'LEN(句子)'? – Wondercricket
'sentence.split(“,”)'每次找到该字符时都会尝试查找“,”并分割句子。它没有',',所以它不会分裂它 –