A packing checklist gains one new task.
What You Need to Understand
list.append(item) adds one object to the end of a list. If that object is itself a list, it is added as a single nested element.
When to Use It
A packing checklist gains one new task.
Step-by-Step Python Example
tasks = ["pack", "label"]
result = tasks.append("ship")
print(tasks)
print(result)
How the Example Works
The list now has three entries, and the method returned None because it changed the list in place.
Example Output
['pack', 'label', 'ship']
None
['core', ['extra', 'optional']]
A Second Example
Compare this smaller variation with the main example, then experiment with your own values.
groups = ["core"]
groups.append(["extra", "optional"])
print(groups)
Important Behavior and Edge Cases
Do not assign tasks = tasks.append("ship"): that replaces your list variable with None.
Try It Yourself
Append a list of two tags to a list and inspect whether it creates one nested item.
Common Beginner Mistakes
- Do not assign
tasks = tasks.append("ship"): that replaces your list variable withNone. - Using the wrong collection method for this operation without checking whether it mutates the object, returns a result, or raises on missing data.
Key Takeaways
list.append(item)adds one object to the end of a list.- The list now has three entries, and the method returned
Nonebecause it changed the list in place. - Do not assign
tasks = tasks.append("ship"): that replaces your list variable withNone.