AttributeError: 'int' object has no attribute (Fix)

Fix the error AttributeError: 'int' object has no attribute by finding where a number is being used like a string, list, dictionary, or custom object.

This usually means a variable contains an int, but your code is trying to use a method or attribute that belongs to some other type.

Quick fix

value = 123

# Wrong: integers do not have string methods
# print(value.lower())

# Fix 1: convert to string first
print(str(value).lower())

# Fix 2: check the type before calling an attribute
if isinstance(value, str):
    print(value.lower())
else:
    print(value)

This error happens when you call a method or access an attribute that integers do not have, such as .lower(), .append(), .keys(), or a custom attribute name.

What this error means

Python is telling you:

  • It found an integer value such as 5, 100, or -3
  • Your code tried to use an attribute or method on that integer
  • That attribute does not exist for int
  • The real problem is often that the variable has a different type than you expected

For example, this will fail because .lower() is a string method, not an integer method:

value = 100
print(value.lower())

Simple example that causes the error

Here is a small example:

value = 123
print(value.lower())

Output:

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

Why this happens:

  • value contains the integer 123
  • .lower() works on strings such as "HELLO"
  • Integers do not have a .lower() method

Correct version:

value = 123
print(str(value).lower())

Output:

123

If you need help with string behavior, see Python strings explained.

Common causes

This error often happens in one of these situations:

  • Using string methods on a number, such as .lower(), .strip(), or .split()
  • Using list methods on a number, such as .append()
  • Using dictionary methods on a number, such as .keys() or .get()
  • Overwriting a variable with an integer later in the program
  • Converting input with int() and then forgetting the value is no longer a string
  • A function returns an integer but you treat it like an object with custom attributes

Examples of common mistakes:

value = 10
value.append(20)   # int has no .append()
value = 42
print(value.keys())   # int has no .keys()
user_input = int(input("Enter a number: "))
print(user_input.strip())   # .strip() works on strings, not ints

How to fix it

Start with the simplest check: inspect the value and its type.

value = 123

print(value)
print(type(value))

Output:

123
<class 'int'>

Useful steps:

  • Print the variable and its type with print(value, type(value))
  • Check where the variable was last assigned
  • Use the correct method for the actual type
  • Convert the value first if needed, such as str(number)
  • Rename variables clearly so you do not confuse text values and number values
  • Add isinstance() checks when the type may change

The built-in type() function and isinstance() function are especially helpful for this kind of bug.

Fix example: convert to the right type

If your goal is to use string methods, convert the integer to a string first.

Wrong

value = 456
print(value.split())
value = 456
text = str(value)
print(text.split())

Output:

['456']

Another example with .lower():

value = 123
text = str(value)
print(text.lower())

Output:

123

If your real goal is math, do not convert to a string. Keep the value as an integer and use numeric operations instead.

value = 123
print(value + 10)

Output:

133

If you specifically need this conversion, see how to convert int to string in Python.

Fix example: find accidental reassignment

A variable may start as one type and later become an integer.

Example that fails

value = "HELLO"
print(value.lower())

value = 100
print(value.lower())

Output:

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

The problem is that value was reassigned.

A simple way to debug this is to print the variable before the failing line:

value = "HELLO"
print(value.lower())

value = 100

print("Before lower():", value)
print("Type:", type(value))

print(value.lower())

Output:

hello
Before lower(): 100
Type: <class 'int'>
AttributeError: 'int' object has no attribute 'lower'

A better fix is to use clearer variable names:

message = "HELLO"
print(message.lower())

count = 100
print(count + 1)

This is a very common mistake in longer scripts and loops.

Beginner debugging steps

When you see this error, follow these steps:

  1. Read the full error message carefully
  2. Find the line that caused the problem
  3. Print the variable right before that line
  4. Print type(variable) to confirm it is an int
  5. Search earlier in the code for where that variable was assigned
  6. Check function return values if the variable came from a function
  7. Make sure your fix matches the type you actually want

These commands are useful while debugging:

print(value)
print(type(value))
print(isinstance(value, int))
print(isinstance(value, str))
print(dir(value))

What they do:

  • print(value) shows the current value
  • print(type(value)) shows the exact type
  • print(isinstance(value, int)) checks whether it is an integer
  • print(isinstance(value, str)) checks whether it is a string
  • print(dir(value)) shows available attributes and methods

If you are new to debugging, read this beginner guide to debugging Python code.

Sometimes the problem is similar, but the type is different.

You may also want to check:

Common mistakes

These are very common beginner mistakes that cause this error:

  • Calling .lower() on an integer
  • Calling .append() on an integer
  • Calling .keys() on an integer
  • Reusing a variable name and changing it from string to int
  • Using int(input(...)) and later treating the result like text
  • Expecting a custom object but receiving a plain integer

For example:

age = int(input("Enter your age: "))
print(age.strip())

This fails because age is already an integer after int(...).

If you wanted text methods like .strip(), do them before converting:

age_text = input("Enter your age: ").strip()
age = int(age_text)
print(age)

FAQ

Why does Python say an int has no attribute?

Because your variable currently holds an integer, and the attribute or method you used does not exist for integers.

How do I know which variable is an int?

Check the traceback, then print the variable and its type right before the line that fails.

Can I use string methods on a number?

Not directly. Convert the number to a string first with str(number) if that matches your goal.

Why did this work earlier but fail now?

The variable may have been reassigned later in the code and changed from another type to int.

See also