Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Append() Method | List
Python Data Structures

Append() MethodAppend() Method

Let's create a list named states:

The list has four items. Imagine we want to add a fifth state, say Ohio. Here's how we do it:

The code above has added Ohio to the end of the list. The list now contains five items. states[4] refers to Ohio.

If we want to add a number instead of a string, we don't use quotation marks. Here's how it's done:

The code above has added the number 10 to the end of the list. The list now includes six items. states[5] refers to 10.

Note

The append() function allows you to add only one item at a time.

Завдання

You have a list named fruits with these items:

'Raspberry', 'Pomegranate', 'Peach', 'Pear'.

You need to add the following items to the existing list:

'Mango', 'Banana'.

Все було зрозуміло?

Секція 1. Розділ 7
toggle bottom row
course content

Зміст курсу

Python Data Structures

Append() MethodAppend() Method

Let's create a list named states:

The list has four items. Imagine we want to add a fifth state, say Ohio. Here's how we do it:

The code above has added Ohio to the end of the list. The list now contains five items. states[4] refers to Ohio.

If we want to add a number instead of a string, we don't use quotation marks. Here's how it's done:

The code above has added the number 10 to the end of the list. The list now includes six items. states[5] refers to 10.

Note

The append() function allows you to add only one item at a time.

Завдання

You have a list named fruits with these items:

'Raspberry', 'Pomegranate', 'Peach', 'Pear'.

You need to add the following items to the existing list:

'Mango', 'Banana'.

Все було зрозуміло?

Секція 1. Розділ 7
toggle bottom row
some-alt