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

Course Content

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

bookTuples (3/3)

Like for lists, you can place tuples inside tuples! And then you can use double indexing to reach the element in tuple inside a tuple.

For example, for out five countries

CountryAreaPopulation
USA9629091331002651
Canada998467037742154
Germany35711483783942
Brazil8515767212559417
India31663911380004385
1234567
# create two-dimensional tuple two_d_countries = (('USA', 9629091, 331002651), ('Canada', 9984670, 37742154), ('Germany', 357114, 83783942), ('Brazil', 8515767, 212559417), ('India', 3166391, 1380004385)) # information about India print(two_d_countries[4]) # area of Canada print(two_d_countries[1][1])
copy

Task

Create two-dimensional tuple for people below in format (("name", age, height), ("name", age, height)):

NameAgeHeight
Alex23178
Noah34189
Peter29175
John41185
Michelle35165
  1. Print information for Peter.
  2. Print height of John.
  3. Print tuple converted into list (use list function)

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 6
toggle bottom row

bookTuples (3/3)

Like for lists, you can place tuples inside tuples! And then you can use double indexing to reach the element in tuple inside a tuple.

For example, for out five countries

CountryAreaPopulation
USA9629091331002651
Canada998467037742154
Germany35711483783942
Brazil8515767212559417
India31663911380004385
1234567
# create two-dimensional tuple two_d_countries = (('USA', 9629091, 331002651), ('Canada', 9984670, 37742154), ('Germany', 357114, 83783942), ('Brazil', 8515767, 212559417), ('India', 3166391, 1380004385)) # information about India print(two_d_countries[4]) # area of Canada print(two_d_countries[1][1])
copy

Task

Create two-dimensional tuple for people below in format (("name", age, height), ("name", age, height)):

NameAgeHeight
Alex23178
Noah34189
Peter29175
John41185
Michelle35165
  1. Print information for Peter.
  2. Print height of John.
  3. Print tuple converted into list (use list function)

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 5. Chapter 6
toggle bottom row

bookTuples (3/3)

Like for lists, you can place tuples inside tuples! And then you can use double indexing to reach the element in tuple inside a tuple.

For example, for out five countries

CountryAreaPopulation
USA9629091331002651
Canada998467037742154
Germany35711483783942
Brazil8515767212559417
India31663911380004385
1234567
# create two-dimensional tuple two_d_countries = (('USA', 9629091, 331002651), ('Canada', 9984670, 37742154), ('Germany', 357114, 83783942), ('Brazil', 8515767, 212559417), ('India', 3166391, 1380004385)) # information about India print(two_d_countries[4]) # area of Canada print(two_d_countries[1][1])
copy

Task

Create two-dimensional tuple for people below in format (("name", age, height), ("name", age, height)):

NameAgeHeight
Alex23178
Noah34189
Peter29175
John41185
Michelle35165
  1. Print information for Peter.
  2. Print height of John.
  3. Print tuple converted into list (use list function)

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Like for lists, you can place tuples inside tuples! And then you can use double indexing to reach the element in tuple inside a tuple.

For example, for out five countries

CountryAreaPopulation
USA9629091331002651
Canada998467037742154
Germany35711483783942
Brazil8515767212559417
India31663911380004385
1234567
# create two-dimensional tuple two_d_countries = (('USA', 9629091, 331002651), ('Canada', 9984670, 37742154), ('Germany', 357114, 83783942), ('Brazil', 8515767, 212559417), ('India', 3166391, 1380004385)) # information about India print(two_d_countries[4]) # area of Canada print(two_d_countries[1][1])
copy

Task

Create two-dimensional tuple for people below in format (("name", age, height), ("name", age, height)):

NameAgeHeight
Alex23178
Noah34189
Peter29175
John41185
Michelle35165
  1. Print information for Peter.
  2. Print height of John.
  3. Print tuple converted into list (use list function)

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 5. Chapter 6
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt