How do you add a new item to a list in Python?
Experience Level: Junior
Tags: Python
Answer
To add a new item to a list, use .append() method.
Example:
items = list["red", "amber"]
items.append("green")
Related Python job interview questions
How do you comment out code in Python using single-line comment?
Python JuniorHow do you delete an item from a list in Python?
Python JuniorHow do you display a number of items in a list in Python?
Python JuniorWhat is a private method in Python?
Python JuniorWhy would you use a private method in Python?
Python Junior