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


#1



https://www.codecademy.com/courses/python-beginner-2W5v7/0/4?curriculum_id=4f89dab3d788890003000096#


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")
original=raw_input

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


#2

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

original = raw_input("enter a word")

#3

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?


#4

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 ...

original=raw_input

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.


#5

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