Home » How-To » How to Fix “Object of Type ‘int’ has no len()”

How to Fix “Object of Type ‘int’ has no len()”

Are you getting an “Object of Type ‘int’ has no len()” error in Python?

Basically, an integer by design is to count up a number of apples or a number of people.

You cannot break it down to constituent parts like a hundred is made up of 10, 20, 30, etc.

It cannot be viewed as having a length as a description of the number of currents of an object.

It cannot be 90+10 or 99+1, it’s just one figure (e.g. 100).

Hence, if you’re trying to call a method on an “int” type of variable, you will get an error.

In this guide, you’ll learn how to fix “Object of Type ‘int’ has no len()” in Python, Django, Flask, Gekko, or Geopandas.

How to Fix “Object of Type ‘int’ has no len()”

Object of Type 'int' has no len()

Before (Wrong):

data = 100

If you run this command, you’ll get the “TypeError: object of type ‘int’ has no len()” error.

This is because you’re trying to call a method on an “int” type of variable.

There are a few methods to fix this.

Fix 1 (Correct):

data = "100"
print("Length of string is ", len(data))
data = [100,200,300]

Fix 2 (Correct):

data = "100"
print("Length of list is ", len(data))
data = [100,200,300]

Fix 3 (Correct):

data = "100"
print("Length of tuple is ", len(data))
data = {"Age": 1, "Name": 2}

Fix 4 (Correct):

data = "100"
print("Length of a dictionary is ", len(data))

The most common reason for the error is that you’re trying to call a method on an “int” type of variable.

This will only work if you called a “len()” function on a “list” type of variable.

Further reading

How to Fix “Uncaught SyntaxError: Cannot use import statement outside a module”

How to Fix “python: can’t open file ‘manage.py’: [Errno 2] No such file or directory”

Best Binance Referral ID Code in 2022

About the author

Lim How Wei

Lim How Wei is the founder of followchain.org, with 8+ years of experience in Social Media Marketing and 4+ years of experience as an active investor in stocks and cryptocurrencies. He has researched, tested, and written thousands of articles ranging from social media platforms to messaging apps.

Lim has been quoted and referenced by major publications and media companies like WikiHow, Fast Company, HuffPost, Vice, New York Post, The Conversation, and many others. One of his articles about the gig economy was quoted by Joe Rogan who hosts The Joe Rogan Experience (arguably the most popular podcast in the world), in the This Past Weekend podcast by Theo Von.

In his free time, Lim plays multiple games like Genshin Impact, League of Legends, Counter-Strike, Hearthstone, RuneScape, and many others. He creates guides, walkthroughs, solutions, and more on games that he plays to help other players with their progression.