What is the primary difference between the methods append() and extend() when applied to a list?
- append() adds one item
- append() extends lists
- extend() adds elements
- extend() appends lists
The primary difference between append() and extend() is that append() adds a single item to the end of a list, while extend() adds the elements of an iterable (e.g., another list) to the end of the list. This means extend() is used to combine two lists, while append() adds an element as it is, even if it's a list itself.
Loading...
Related Quiz
- What keyword is used in Python to make a decision?
- How can you prevent overfitting in a deep learning model developed with TensorFlow or PyTorch?
- How do you define a floating-point variable in Python?
- How would you enable Cross-Origin Resource Sharing (CORS) in a Flask application?
- For an infinite loop using the while construct, the typical condition used is while _______: