Object 'int' has no attribute 'startswith'

I am getting weird error. '' int 'object has no' startswith 'attribute "

I haven't used the word "startswith" in my python program.? Can anyone fix this - or what is it referring to?

+2


a source to share


2 answers


Something in your program is trying to call a method on an startswith

object, probably because it expects it to be a string. You need to pay attention to the traceback to see what it's called on and why it's an integer instead of a string. Did you miss an integer where the string was expected?



+12


a source


startswith

only works with strings

.

If you need to check if it starts int

with a set of numbers, you can convert it to string

, i.e .:



someint = 1234
if str(someint).startswith("123"):
    # do somenting

      

+2


a source







All Articles