Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Tuples (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

Tuples (1/3)

Tuples - is one more type of data available in Python. Tuples are usually used when we have a description of some object (such as point coordinates, characteristics of a car, etc...). Tuples may contain data of different types inside, but unlike lists - they are immutable. If you can modify the list by using, for example, list.append() or list.extend(), if you want to modify a tuple, you have to reassign it to a new variable (or the same).

To create tuple use (elem1, elem2, ...) notation or function tuple(x), where x is iterable.

For example, let's create tuple with countries areas and populations.

CountryAreaPopulation
USA9629091331002651
Canada998467037742154
Germany35711483783942
123
# create tuple countries_tuple = ("USA", 9629091, 331002651, "Canada", 9984670, 37742154, "Germany", 357114, 83783942) print(countries_tuple)
copy

Tarea

Create the tuple (people_tuple) for the people below and print it:

NameAgeHeight
Alex23178
Noah34189
Peter29175

Tarea

Create the tuple (people_tuple) for the people below and print it:

NameAgeHeight
Alex23178
Noah34189
Peter29175

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

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

Tuples (1/3)

Tuples - is one more type of data available in Python. Tuples are usually used when we have a description of some object (such as point coordinates, characteristics of a car, etc...). Tuples may contain data of different types inside, but unlike lists - they are immutable. If you can modify the list by using, for example, list.append() or list.extend(), if you want to modify a tuple, you have to reassign it to a new variable (or the same).

To create tuple use (elem1, elem2, ...) notation or function tuple(x), where x is iterable.

For example, let's create tuple with countries areas and populations.

CountryAreaPopulation
USA9629091331002651
Canada998467037742154
Germany35711483783942
123
# create tuple countries_tuple = ("USA", 9629091, 331002651, "Canada", 9984670, 37742154, "Germany", 357114, 83783942) print(countries_tuple)
copy

Tarea

Create the tuple (people_tuple) for the people below and print it:

NameAgeHeight
Alex23178
Noah34189
Peter29175

Tarea

Create the tuple (people_tuple) for the people below and print it:

NameAgeHeight
Alex23178
Noah34189
Peter29175

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

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

Tuples (1/3)

Tuples - is one more type of data available in Python. Tuples are usually used when we have a description of some object (such as point coordinates, characteristics of a car, etc...). Tuples may contain data of different types inside, but unlike lists - they are immutable. If you can modify the list by using, for example, list.append() or list.extend(), if you want to modify a tuple, you have to reassign it to a new variable (or the same).

To create tuple use (elem1, elem2, ...) notation or function tuple(x), where x is iterable.

For example, let's create tuple with countries areas and populations.

CountryAreaPopulation
USA9629091331002651
Canada998467037742154
Germany35711483783942
123
# create tuple countries_tuple = ("USA", 9629091, 331002651, "Canada", 9984670, 37742154, "Germany", 357114, 83783942) print(countries_tuple)
copy

Tarea

Create the tuple (people_tuple) for the people below and print it:

NameAgeHeight
Alex23178
Noah34189
Peter29175

Tarea

Create the tuple (people_tuple) for the people below and print it:

NameAgeHeight
Alex23178
Noah34189
Peter29175

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Tuples - is one more type of data available in Python. Tuples are usually used when we have a description of some object (such as point coordinates, characteristics of a car, etc...). Tuples may contain data of different types inside, but unlike lists - they are immutable. If you can modify the list by using, for example, list.append() or list.extend(), if you want to modify a tuple, you have to reassign it to a new variable (or the same).

To create tuple use (elem1, elem2, ...) notation or function tuple(x), where x is iterable.

For example, let's create tuple with countries areas and populations.

CountryAreaPopulation
USA9629091331002651
Canada998467037742154
Germany35711483783942
123
# create tuple countries_tuple = ("USA", 9629091, 331002651, "Canada", 9984670, 37742154, "Germany", 357114, 83783942) print(countries_tuple)
copy

Tarea

Create the tuple (people_tuple) for the people below and print it:

NameAgeHeight
Alex23178
Noah34189
Peter29175

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 5. Capítulo 4
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt