1089
1089

Reputation: 109

AttributeError: 'builtin_function_or_method' object has no attribute 'replace'

When I try to use this in my program, it says that there's an attribute error

'builtin_function_or_method' object has no attribute 'replace'

but I don't understand why.

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

Upvotes: 10

Views: 67837

Answers (1)

user2555451
user2555451

Reputation:

You need to call the str.lower method by placing () after it:

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

Otherwise, first and second will be assigned to the function object itself:

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

Upvotes: 11

Related Questions