Last modified: Dec 06, 2025 By Alexander Williams

Fix Python TypeError: Can't Concatenate List and Int

This error is common in Python. It happens when you try to merge incompatible data types.

Specifically, you try to add a list and an integer with the + operator. Python does not allow this.

This guide will explain why it happens. You will learn how to fix it correctly.

Understanding the Error Message

The error message is very direct. It tells you the exact problem.

Python says it "can only concatenate list to list". The + operator is for joining two sequences.

You tried to use it with a list and an integer. An integer is not a sequence like a list.

This causes a TypeError. Python cannot perform the operation.

Common Cause: The + Operator Misuse

The most frequent cause is misusing +. This operator concatenates sequences.

It works for lists, strings, and tuples. It does not work for mixing a list with a single number.

Look at this example that triggers the error.


# Trying to add an integer to a list incorrectly
my_list = [1, 2, 3]
result = my_list + 5  # This line causes the TypeError

Traceback (most recent call last):
  File "script.py", line 3, in 
    result = my_list + 5
TypeError: can only concatenate list (not "int") to list

The code tries to add the integer 5 to the list. This is not a valid operation in Python.

The + expects another list. You provided a single integer.

This is different from a TypeError with 'int' and 'str' but stems from similar type confusion.

Solution 1: Use the append() Method

To add a single element to a list, use the append() method. It modifies the original list.

The append() method adds its argument as a single item to the end of the list.

Here is the correct way to do it.


# Correct way to add a single element
my_list = [1, 2, 3]
my_list.append(5)  # Use the append method
print(my_list)

[1, 2, 3, 5]

The append() method works in-place. It changes the my_list variable directly.

It does not return a new list. It returns None.

Solution 2: Use the extend() Method

Use extend() if you want to add multiple items from another sequence.

The extend() method takes an iterable. It adds each element from that iterable to the list.

This is useful for combining lists.


# Using extend to add multiple items
list_a = [1, 2, 3]
list_b = [4, 5]
list_a.extend(list_b)  # Adds items from list_b
print(list_a)

[1, 2, 3, 4, 5]

You can also use extend() with other iterables like tuples or strings.

Remember, extend() adds elements, not the whole object as one item.

Solution 3: Wrap the Integer in a List

If you must use the + operator, convert the integer to a list first.

Wrap the single integer in square brackets []. This creates a one-element list.

Now you can concatenate two lists with +.


# Using + by converting int to a list first
my_list = [1, 2, 3]
result = my_list + [5]  # 5 is now inside a list
print(result)

[1, 2, 3, 5]

This creates a new list called result. The original my_list remains unchanged.

This method is less common than append(). It is useful for creating new lists.

Solution 4: Using List Comprehension

List comprehension is a powerful tool. It can be used to build new lists from existing ones.

You can create a new list that includes the original items plus new ones.

This is a very Pythonic approach.


# Using list comprehension to create a new list
my_list = [1, 2, 3]
new_element = 5
result = [item for item in my_list] + [new_element]
print(result)

[1, 2, 3, 5]

This method is flexible. You can add conditions or transform items inside the comprehension.

Debugging and Type Checking

Always check the data type of your variables. Use the type() function.

This helps prevent many TypeErrors, not just this one.

For example, issues like a 'numpy.ndarray' object is not callable error also benefit from type awareness.


# Debugging with type()
my_list = [1, 2, 3]
my_int = 5
print(type(my_list))  # Output: 
print(type(my_int))   # Output: 

Knowing the types helps you choose the right operation.

If you expect a list but get an integer, you found the bug's source.

Common Pitfalls and Related Errors

This error often occurs in loops. You might accidentally add a number instead of a list.

It can also happen when functions return unexpected types.

Be careful with operations that change types. For instance, a TypeError: can't convert 'int' to str is another common type mismatch.


# Pitfall in a loop
numbers = [10, 20, 30]
total = []
for num in numbers:
    # total = total + num  # WRONG: This causes the TypeError
    total.append(num)      # CORRECT: Use append
print(total)

Always plan your variable types. Stick to consistent operations.

Conclusion

The "can only concatenate list" error is straightforward. It stops you from mixing incompatible types.

The fix is simple. Use append() to add a single item.

Use extend() or + with another list to add multiple items.

Understanding Python's data types is key. It prevents this and many other errors.

Always test your code with the type() function when unsure.

Now you can fix this error quickly and keep coding.