当我尝试在我的程序中使用它时,它表示存在属性错误
'builtin_function_or_method' object has no attribute 'replace'
但我不明白为什么。
def verify_anagrams(first, second):
first=first.lower
second=second.lower
first=first.replace(' ','')
second=second.replace(' ','')
a='abcdefghijklmnopqrstuvwxyz'
b=len(first)
e=0
for i in a:
c=first.count(i)
d=second.count(i)
if c==d:
e+=1
return b==e
答案 0 :(得分:6)
您需要<{>}调用 str.lower
方法,然后将()
放在其后:
first=first.lower()
second=second.lower()
否则,first
和second
将分配给函数对象本身:
>>> first = "ABCDE"
>>> first = first.lower
>>> first
<built-in method lower of str object at 0x01C765A0>
>>>
>>> first = "ABCDE"
>>> first = first.lower()
>>> first
'abcde'
>>>