Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lists (1/3) | Other data types
Learn Python from Scratch
course content

Contenido del Curso

Learn Python from Scratch

Learn Python from Scratch

1. The basics
2. Arithmetic operations
3. Common data types
4. Conditional statements
5. Other data types
6. Loops
7. Functions

bookLists (1/3)

List - is one of the data structures in Python. It allows storing inside itself variables of different types, such as numbers, strings, tuples, dictionaries... (which will be discussed later).

To create a list, use [] brackets and put inside them variables/values you want to store in the list. Also, you can convert one variable into a list (this variable type has to be iterable, like string, list, or tuple).

For example, we can create a list with countries' names and their population.

123
# create list with countries and their areas countries = ["USA", 9629091, "Canada", 9984670, "Germany", 357114] print(countries)
copy

The indexation of elements is the same as for strings, i.e. the very first element has index 0. For example, let's get information about Canada: name is in the third position (which means the index is 2) and area in the fourth (index 3), so we need to write 2:4 (right limit is not inclusive, as you remember).

123
# elements from 2 to 3 in our list countries = ["USA", 9629091, "Canada", 9984670, "Germany", 357114] print(countries[2:4])
copy

Tarea

Create variable people and store the names of people with their ages. Then print your list.

NameAge
Alex23
Noah34
Peter29

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 1
toggle bottom row

bookLists (1/3)

List - is one of the data structures in Python. It allows storing inside itself variables of different types, such as numbers, strings, tuples, dictionaries... (which will be discussed later).

To create a list, use [] brackets and put inside them variables/values you want to store in the list. Also, you can convert one variable into a list (this variable type has to be iterable, like string, list, or tuple).

For example, we can create a list with countries' names and their population.

123
# create list with countries and their areas countries = ["USA", 9629091, "Canada", 9984670, "Germany", 357114] print(countries)
copy

The indexation of elements is the same as for strings, i.e. the very first element has index 0. For example, let's get information about Canada: name is in the third position (which means the index is 2) and area in the fourth (index 3), so we need to write 2:4 (right limit is not inclusive, as you remember).

123
# elements from 2 to 3 in our list countries = ["USA", 9629091, "Canada", 9984670, "Germany", 357114] print(countries[2:4])
copy

Tarea

Create variable people and store the names of people with their ages. Then print your list.

NameAge
Alex23
Noah34
Peter29

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 1
toggle bottom row

bookLists (1/3)

List - is one of the data structures in Python. It allows storing inside itself variables of different types, such as numbers, strings, tuples, dictionaries... (which will be discussed later).

To create a list, use [] brackets and put inside them variables/values you want to store in the list. Also, you can convert one variable into a list (this variable type has to be iterable, like string, list, or tuple).

For example, we can create a list with countries' names and their population.

123
# create list with countries and their areas countries = ["USA", 9629091, "Canada", 9984670, "Germany", 357114] print(countries)
copy

The indexation of elements is the same as for strings, i.e. the very first element has index 0. For example, let's get information about Canada: name is in the third position (which means the index is 2) and area in the fourth (index 3), so we need to write 2:4 (right limit is not inclusive, as you remember).

123
# elements from 2 to 3 in our list countries = ["USA", 9629091, "Canada", 9984670, "Germany", 357114] print(countries[2:4])
copy

Tarea

Create variable people and store the names of people with their ages. Then print your list.

NameAge
Alex23
Noah34
Peter29

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

List - is one of the data structures in Python. It allows storing inside itself variables of different types, such as numbers, strings, tuples, dictionaries... (which will be discussed later).

To create a list, use [] brackets and put inside them variables/values you want to store in the list. Also, you can convert one variable into a list (this variable type has to be iterable, like string, list, or tuple).

For example, we can create a list with countries' names and their population.

123
# create list with countries and their areas countries = ["USA", 9629091, "Canada", 9984670, "Germany", 357114] print(countries)
copy

The indexation of elements is the same as for strings, i.e. the very first element has index 0. For example, let's get information about Canada: name is in the third position (which means the index is 2) and area in the fourth (index 3), so we need to write 2:4 (right limit is not inclusive, as you remember).

123
# elements from 2 to 3 in our list countries = ["USA", 9629091, "Canada", 9984670, "Germany", 357114] print(countries[2:4])
copy

Tarea

Create variable people and store the names of people with their ages. Then print your list.

NameAge
Alex23
Noah34
Peter29

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 5. Capítulo 1
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt