Last modified: Apr 24, 2026 By Alexander Williams
Fix Float Object Subscriptable Error
Have you seen the error TypeError: 'float' object is not subscriptable?
This error is common in Python. It happens when you try to use square brackets on a float number.
Square brackets are for lists, dictionaries, and strings. Floats are single values. You can't index them.
In this article, you will learn what causes this error. You will also see simple fixes with code examples.
What Does Subscriptable Mean?
A subscriptable object is something you can index with square brackets. Lists, tuples, strings, and dictionaries are subscriptable.
For example, you can get the first character of a string like this:
text = "Python"
first_char = text[0]
print(first_char) # Output: P
Floats are not subscriptable. They are single numbers. You cannot do 3.14[0].
Common Causes of This Error
1. Accidentally Using a Float as a List
You might think you have a list, but it is actually a float. This often happens when you read data from a file or user input.
# Wrong: treating a float like a list
price = 29.99
print(price[0]) # Error here
Output:
TypeError: 'float' object is not subscriptable
2. Confusing Float with List of Numbers
Sometimes you expect a list but get a single float. Check your data source carefully.
# Wrong assumption
data = 45.67 # This is a float, not a list
print(data[0]) # Error
3. Using Indexing on a Returned Float
A function might return a float. If you try to subscript the result, you get the error.
def get_average():
return 88.5
avg = get_average()
print(avg[0]) # Error: float is not subscriptable
How to Fix the Error
Fix 1: Check Your Variable Type
Use the type() function to see what your variable actually is.
price = 29.99
print(type(price)) # <class 'float'>
# Now you know it's a float, not a list
Fix 2: Convert Float to String If You Need Indexing
If you need to access digits of a float, convert it to a string first.
price = 29.99
price_str = str(price)
print(price_str[0]) # Output: '2'
print(price_str[1]) # Output: '9'
Fix 3: Use a List Instead of a Single Float
If your data should be multiple values, store them in a list.
# Correct: use a list
prices = [29.99, 45.50, 12.75]
print(prices[0]) # Output: 29.99
print(prices[1]) # Output: 45.5
Fix 4: Handle Function Returns Properly
If a function returns a float, do not try to index it. Use it as a single value.
def get_average():
return 88.5
avg = get_average()
print(avg) # Output: 88.5
# No indexing needed
Real-World Example
Imagine you are reading prices from a file. Each line might have one price. If you read it wrong, you get a float error.
# Simulating reading from file
line = "29.99"
price = float(line) # This is a float
# Wrong: trying to get first digit
# print(price[0]) # Error
# Correct: convert to string if needed
price_str = str(price)
print(price_str[0]) # Output: '2'
How to Debug This Error
When you see this error, follow these steps:
- Look at the line number in the traceback.
- Check the variable you are indexing with
type(). - If it is a float, decide if you need a list or a string.
- Use
str()to convert if you need individual characters. - Use a list if you need multiple values.
For more tips on handling Python errors, read our guide on Python TypeError: Causes and Fixes.
Preventing the Error
Always check your data types before indexing. Use isinstance() to be safe.
def process_data(data):
if isinstance(data, list):
print(data[0])
else:
print("Data is not a list")
Also, validate input from users or files. Convert to proper types early.
Another helpful article is Python TypeError: Causes and Fixes which covers many similar errors.
Conclusion
The TypeError: 'float' object is not subscriptable is easy to fix once you understand it.
Remember: floats are single numbers. You cannot use square brackets on them.
If you need to access parts of a number, convert it to a string. If you need multiple numbers, use a list.
Always check your variable type with type() when debugging. This will save you time.
For more Python error solutions, check our Python TypeError: Causes and Fixes article.
Practice with the examples above. Soon you will spot this error quickly and fix it without stress.