Search code examples
pythonattributeerror

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


When I try to use the "isalpha()" function like here:

def find_chars(string):
  num_letter = 0
  num_int = 0
  num_spec = 0

  for i in string:
    i_str = i.lower
    if i_str.isalpha():
      num_str +=1 
    elif i.isdigit():
      num_int += 1
    else:
      num_spec += 1
  return num_letter, num_int, num_spec

I get the following

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

I am using python 3.6.9 if that helps (using google colab)


Solution

  • The problem is in the line above

    i_str = i.lower
    

    should be:

    i_str = i.lower()
    

    The type of i_str changed to function with that assignment.