Last modified: Dec 09, 2025 By Alexander Williams

Fix AttributeError: 'int' object has no attribute 'lower'

Python errors can stop your code. The AttributeError is common. It often confuses beginners.

This error means you used a method on the wrong type. The lower() method is for strings.

You cannot call it on an integer. This guide explains why it happens. We will show you how to fix it.

Understanding the Error Message

Let's break down the error message. "AttributeError: 'int' object has no attribute 'lower'".

An AttributeError occurs when you try to access an attribute. Or call a method that does not exist.

Here, Python tells you the object is an 'int'. Integers do not have a lower() method.

This method converts string characters to lowercase. It is only defined for string objects.

Common Causes of the Error

This error has a few common causes. The main cause is a type mismatch.

You might think a variable is a string. But it is actually an integer.

This often happens with user input or data from files. Another cause is incorrect variable assignment.

You may have reassigned a variable by mistake. Let's look at examples.

Cause 1: Direct Integer Assignment

This is the simplest case. You try to call lower() on a number.


# Trying to use .lower() on an integer
my_number = 42
result = my_number.lower()  # This line causes the error

AttributeError: 'int' object has no attribute 'lower'

Cause 2: Mixed Data Types in Collections

You might have a list or tuple. It contains both strings and integers.

Looping and applying lower() will fail on the integers.


# A list with mixed types
data = ["HELLO", 100, "WORLD"]
for item in data:
    print(item.lower())  # Fails on the integer 100

Cause 3: Input from User or External Source

User input comes as a string. But you might convert it to an integer later.

If you forget the type changed, you get the error. This is a common logic mistake.


user_value = input("Enter a number: ")  # e.g., "123"
# Convert to integer for calculation
user_value = int(user_value)
# Later, mistakenly treat it as a string
print(user_value.lower())  # Error!

How to Fix the AttributeError

Fixing the error requires ensuring the object is a string. You must check the type before calling lower().

Use type checking or conversion. Let's explore solutions.

Solution 1: Convert the Integer to a String

Use the str() function. It converts the integer to a string.

Then you can safely call lower(). This is useful for formatting output.


my_number = 42
# Convert integer to string first
number_string = str(my_number)
# Now .lower() works, but on the string representation "42"
result = number_string.lower()
print(result)  # Output: "42"

42

Solution 2: Check the Type Before Calling

Use isinstance() to check the object type. This is a defensive programming practice.

It prevents errors in complex code. You can handle different types appropriately.


def process_value(value):
    if isinstance(value, str):
        return value.lower()
    elif isinstance(value, int):
        # Decide what to do with integers
        return str(value)  # Or handle differently
    else:
        # Handle other types
        return value

print(process_value("HELLO"))  # Output: hello
print(process_value(100))      # Output: "100"

Solution 3: Ensure Data Consistency

Clean your data first. Ensure all items in a collection are strings.

You can use a list comprehension. Convert all items to strings.

This is similar to fixing a Fix AttributeError: 'list' object has no attribute 'split' error.


data = ["HELLO", 100, "WORLD", 3.14]
# Convert every item to a string
string_data = [str(item) for item in data]
# Now safely apply .lower()
lowered_data = [item.lower() for item in string_data]
print(lowered_data)

['hello', '100', 'world', '3.14']

Debugging Tips and Best Practices

Always know your variable types. Use the type() function to check.

Print the type when unsure. This helps trace the source of the error.


value = some_function()
print(f"The type is: {type(value)}")  # Debugging line

Use meaningful variable names. Names like user_input_str indicate the type.

Validate external data. User input, file data, or API responses can be unpredictable.

Consider using try-except blocks. They can catch AttributeErrors gracefully.


try:
    result = my_variable.lower()
except AttributeError:
    print("Variable is not a string. Converting...")
    result = str(my_variable).lower()

This approach is also useful for errors like Fix AttributeError: 'NoneType' Object Has No Attribute 'append'.

Related Errors and Concepts

AttributeErrors are common with type confusion. They happen with many data types.

For example, trying to call keys() on a non-dictionary object.

You can learn more in our guide on Fix AttributeError: 'dict' object has no attribute 'keys'.

Similar principles apply. Always check the object type before calling its methods.

Conclusion

The "AttributeError: 'int' object has no attribute 'lower'" is a type error. It is easy to fix.

Remember that lower() is a string method. You cannot use it on integers.

Convert integers to strings with str(). Check types with isinstance().

Clean your data collections. Use defensive programming.

Understanding this error makes you a better programmer. It helps you avoid similar issues.

Keep practicing type handling. Your debugging skills will improve greatly.