20.6 - Adding Elements to a List
Enroll to start learning
You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.
Practice Questions
Test your understanding with targeted questions
What does fruits.append('orange') do?
💡 Hint: Think about where the item is being added.
Use insert() to add 'mango' to index 2 in a list. What would it look like?
💡 Hint: Remember the syntax for insert.
4 more questions available
Interactive Quizzes
Quick quizzes to reinforce your learning
What does the append() method do?
💡 Hint: Remember it's about the position of the addition.
Using insert(), what happens if you specify index 0?
💡 Hint: Think about how lists are indexed.
Get performance evaluation
Challenge Problems
Push your limits with advanced challenges
Create a list of your favorite animals, and write a function that takes an animal name as an argument. If that animal is not in the list, append it; if it is, insert a new type of the same animal at the same position.
💡 Hint: You'll want to check for membership before you decide what to do.
Imagine you manage a food list. Write a short script to ask users to input food items, appending them until they type 'quit'. After that, allow the user to input one more item that should be inserted at the first position.
💡 Hint: Utilize loops to keep taking inputs!
Get performance evaluation
Reference links
Supplementary resources to enhance your learning experience.