AttributeError: ‘list’ object has no attribute ‘update’ error occurs when you try to operate the update() method on the list object, which does not exist.
Reproduce the error
numbers = [1, 2, 3]
numbers.update(4)
print(numbers)
Output
How to fix the error?
Here are three ways to fix the error.
- Using the list.append()
- Using the list.extend()
- Using the list.insert()
Solution 1: Using the list.append()
You can use the list append() method to add elements to a list.
numbers = [1, 2, 3]
numbers.append(4)
print(numbers)
Output
Solution 2: Using the list.extend()
The list.extend() method extends the list by appending all elements from an iterable-like list.
numbers = [1, 2, 3]
digits = [11, 21, 31]
numbers.extend(digits)
print(numbers)
Output
Solution 3: Using the list.insert()
The list.insert() method will help you add an item at a specific index rather than at the end.
I hope you will use one of these three methods instead of the update() method to prevent the error.
Related posts
AttributeError: ‘list’ object has no attribute ‘copy’
AttributeError: ‘list’ object has no attribute ‘str’
AttributeError: ‘list’ object has no attribute ‘split’

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.