0

I wrote a piece of code in python that reads a string, split it into 2 parts,the first being a string again and the second being an integer. For example

ABDKEK 1255443

The code is as follows:

 L=raw_input()
 ls=L.split()
 num=int(ls[1])
 L=ls[0]
 len=len(L)

and it gives the following error

 len=len(L) 
TypeError: 'int' object is not callable

I make the following change in the code:

 length=len(L)

and it works.

Can anyone explain what does the error 'int' object is not callable mean??

asked Dec 8, 2013 at 4:26
3
  • 1
    Don't use len as a variable name. If you do, you'll no longer be able to access the builtin function named len. Note that you'll get the same error from, e.g., 3(2). An int cannot be called. Commented Dec 8, 2013 at 4:29
  • 1
    Yeah..got it..I had also declared the variable len=0 at the beginning. When I removed it, even len=len(L) works, but then if I try to use len(L) one more time, it gives an error, coz now len is a variable and no longer a built in function. Thanks!! Commented Dec 8, 2013 at 4:38
  • Yup, you got it! Good work :-) Commented Dec 8, 2013 at 4:38

1 Answer 1

4

len is a function name which is already defined and should not be use as a variable. Try some other name instead.

answered Dec 8, 2013 at 4:28
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks.... but I was asking the interpretation of the error.. as in..why the word 'int' was used.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.