AttributeError: 'int' object has no attribute (tested fix)

AttributeError: 'int' object has no attribute 'append' (or 'split', 'lower') means a variable you treat as a list or string actually holds a number. We reproduced the common cases in Python 3.13 and tested the fixes.

1. Calling a list or str method on an int

The attribute name in the message tells you what type you expected the variable to be:

total = 0
for expr in ["total.append(1)", "total.split(',')", "total.lower()", "total.length", "total.isdigit()"]:
    try:
        eval(expr)
    except AttributeError as e:
        print(f"{expr:17} AttributeError: {e}")

Output:

total.append(1)   AttributeError: 'int' object has no attribute 'append'
total.split(',')  AttributeError: 'int' object has no attribute 'split'
total.lower()     AttributeError: 'int' object has no attribute 'lower'
total.length      AttributeError: 'int' object has no attribute 'length'
total.isdigit()   AttributeError: 'int' object has no attribute 'isdigit'

append means you expected a list; split, lower or isdigit mean a str. Find where the variable was set to a number, often a counter that started as 0 or a value parsed from JSON.

2. A dict value initialised to 0 instead of []

counts = {}
counts["a"] = 0
try:
    counts["a"].append(5)          # value is an int, not a list
except AttributeError as e:
    print("AttributeError:", e)
from collections import defaultdict
counts = defaultdict(list)
counts["a"].append(5)
print(dict(counts))

Output:

AttributeError: 'int' object has no attribute 'append'
{'a': [5]}

3. Convert, or use int's own methods

n = 1234
print(str(n).isdigit(), len(str(n)), str(n).zfill(6))   # str methods need str(n)
print(n.bit_length(), (255).to_bytes(1, "big"), n.is_integer())

Output:

True 4 001234
11 b'\xff' True

Call str(n) before using string methods. ints have their own methods such as bit_length() and to_bytes(); int.is_integer() exists only in Python 3.12 and later. Related: 'list' object has no attribute 'split' and object of type 'int' has no len().

Frequently asked questions

How do I fix 'int' object has no attribute 'append'?

The variable holds a number. Initialise it as a list ([] or defaultdict(list)) instead of 0.

How do I fix 'int' object has no attribute 'split'?

Convert first with str(n), or check why the value is an int, for example a JSON number.

Written with AI assistance. Measured on 2026-10-22 on Debian with Python 3.13.5: append, split, lower, length and isdigit on an int, dict values initialised to 0 vs defaultdict(list), and str(n) conversion. Every block was run verbatim and its output pasted unedited. PlainHeaders is our extension; Python is free.