Isn't len(s) a built in function to python, my code says otherwise and I don't know why


After entering a string or null for the raw input I get the same error(below), which I think means the code is breaking at the len() function.

Traceback (most recent call last):
File "python", line 7, in
TypeError: object of type 'builtin_function_or_method' has no len()

This doesn't make sense to me because len(s) is defined as a built in function of python. what am I missing?

raw_input("enter a word")

if len (original) > 0:
    print original
    print "empty"


It's probably the way you're getting and assigning input.. Try this:

original = raw_input("enter a word")


thank you that fixed the issue. I'm not sure why though, do you think that i had the wrong data type or something propagating through the code?


Hi, @cf7190458326 ,

Here you assigned the raw_input function itself to original, rather than assigning the result of calling the raw_input function to original ...


Therefore, when you made this call to the len function, here ...

if len (original) > 0:

... it appeared to the Python interpreter that you were attempting to get the length of a function, which does not have a length.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.