Python 属性错误:';内置函数或方法';对象没有属性';更换';
当我试着在程序中使用它时,它说有一个属性错误Python 属性错误:';内置函数或方法';对象没有属性';更换';,python,string,attributeerror,Python,String,Attributeerror,当我试着在程序中使用它时,它说有一个属性错误 '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=
'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
您需要调用str.lower
方法,方法是将()
放在它后面:
first=first.lower()
second=second.lower()
否则,第一个
和第二个
将分配给函数对象本身:
>>> first = "ABCDE"
>>> first = first.lower
>>> first
<built-in method lower of str object at 0x01C765A0>
>>>
>>> first = "ABCDE"
>>> first = first.lower()
>>> first
'abcde'
>>>
>>first=“ABCDE”
>>>first=first.lower
>>>首先
>>>
>>>first=“ABCDE”
>>>first=first.lower()
>>>首先
“abcde”
>>>
非常感谢您,我看的地方不对!