AttributeError:'builtin_function_or_method'对象没有属性'replace'

时间:2014-07-12 01:28:39

标签: 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='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

1 个答案:

答案 0 :(得分:6)

您需要<{>}调用 str.lower方法,然后将()放在其后:

first=first.lower()
second=second.lower()

否则,firstsecond将分配给函数对象本身:

>>> first = "ABCDE"
>>> first = first.lower
>>> first
<built-in method lower of str object at 0x01C765A0>
>>>
>>> first = "ABCDE"
>>> first = first.lower()
>>> first
'abcde'
>>>