108*_*089 4 python string attributeerror
当我尝试在我的程序中使用它时,它表示存在属性错误
'builtin_function_or_method' object has no attribute 'replace'
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么.
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
Run Code Online (Sandbox Code Playgroud)
你需要调用的str.lower放置方法()后:
first=first.lower()
second=second.lower()
Run Code Online (Sandbox Code Playgroud)
否则,first并且second将被分配到的函数对象本身:
>>> first = "ABCDE"
>>> first = first.lower
>>> first
<built-in method lower of str object at 0x01C765A0>
>>>
>>> first = "ABCDE"
>>> first = first.lower()
>>> first
'abcde'
>>>
Run Code Online (Sandbox Code Playgroud)