bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Python/Foundations
Python•Foundations

Python - Add List Items

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Python - Add List Items?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Order

Put the learning moves in the order that makes the concept easiest to apply.

The insert() method inserts an item at the specified index:
To insert a list item at a specified index, use the insert() method.
To add an item to the end of the list, use the append() method:

Append Items

To add an item to the end of the list, use the append() method:

append()

Insert Items

To insert a list item at a specified index, use the insert() method.

The insert() method inserts an item at the specified index:

Example

thislist = ["apple", "banana", "cherry"]

thislist.insert(1, "orange")

print(thislist)

Note

As a result of the examples above, the lists will now contain 4 items.

Extend List

To append elements from another list to the current list, use the extend() method.

tropical

The elements will be added to the end of the list.

Add Any Iterable

The extend() method does not have to append lists , you can add any iterable object (tuples, sets, dictionaries etc.).

Example

thislist = ["apple", "banana", "cherry"]

thistuple = ("kiwi", "orange")

thislist.extend(thistuple)

print(thislist)

Previous

Python - Change List Items

Next

Python - Remove List Items