對于以下問題:使用正則表達式查找以下字符串中所有名稱的列表。我寫了這段代碼:import redef names(): simple_string = """Amy is 5 years old, and her sister Mary is 2 years old. Ruth and Peter, their parents, have 3 kids.""" names= re.findall("[A-Z][a-z]*", simple_string) print(names) print(len(names))names()它給出了這樣的正確輸出: **['Amy', 'Mary', 'Ruth', 'Peter'] , 4** 但是,當我使用這個時: **assert len(names()) == 4, "There are four names in the simple_string"** 它給了我這個錯誤: **object of type 'NoneType' has no len()** 我不知道函數名稱中的錯誤在哪里,有人可以幫忙嗎?注意:我無法更改斷言函數,它在問題內。
添加回答
舉報
0/150
提交
取消