import re str=r"Alice's Adventures in Wonderland by Lewis Carroll 1865 \ CHAPTER I. Down the Rabbit-Hole \ Alice was beginning to get very tired of sitting by her sister on the \ bank, and of having nothing to do: once or twice she had peeped into the\ book her sister was reading, but it had no pictures or conversations in\ it, 'and what is the use of a book,' thought Alice'without pictures or\ conversation?'" #去除标点符号 str_after_punc = re.sub("['.:,?-]"," ",str) #多个空格合并一个 print(re.sub("_____","空格",str_after_punc))(若涉及空格请用汉字代替空格键) #统计Alice出现的次数,补齐函数 print(str.______________) print("Alice出现次数为:",str._______)