AttributeError: ‘int’ object has no attribute ‘append’

Are you getting the error “‘int’ object has no attribute ‘append’“? Yes, you have come to the right place. In this tutorial, I will show you how to resolve this error.

The error “AttributeError: ‘int’ object has no attribute ‘append’” occurs when we try to call ‘append()‘ on an ‘int‘ not on the list.

[Fixed]: AttributeError: ‘int’ object has no attribute ‘append’

To get rid of this error “AttributeError: ‘int’ object has no attribute ‘append’” you need to make sure the value you are calling “append()” on is of type “List“.

Here is an example of how this error occurs:

my_list = 18

print(type(my_list))  # <class 'int'>

# AttributeError: 'int' object has no attribute 'append'
my_list.append('r')

In the above code, we have an integer “my_list.” And we are using append() on an integer, so we will get this error.

[Fixed]: ModuleNotFoundError: No module named ‘git’

To get rid of this error we need to make sure that my_list is not an integer but a python list.

my_list = [18]

print(type(my_list))  # <class 'list'>
new_list = my_list.append('r')

print(new_list)    #OUTPUT: [18,r]

append() function will append the item at the end of the list. If you are trying to append the element at the specific index then you may also get this error “AttributeError: ‘int’ object has no attribute ‘append’“.

my_list = [18,23,50,10]

# AttributeError: 'int' object has no attribute 'append'
my_list[0].append(3)

print(my_list)

Conclusion on ‘int’ object has no attribute ‘append’

Programmers, we discussed how we can solve this error “‘int’ object has no attribute ‘append’“. If you are still getting this error please let us know in the comments section.

The error “AttributeError: ‘int’ object has no attribute ‘append’” occurs when we try to call ‘append()‘ on ‘int‘ not on the list. To get rid of this error “AttributeError: ‘int’ object has no attribute ‘append’” you need to make sure the value you are calling the ‘append()‘ on type “List”.

Leave a Reply