Tuples (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
Country | Area | Population |
---|---|---|
USA | 9629091 | 331002651 |
Canada | 9984670 | 37742154 |
Germany | 357114 | 83783942 |
Brazil | 8515767 | 212559417 |
India | 3166391 | 1380004385 |
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])
Swipe to start coding
Create two-dimensional tuple for people below in format (("name", age, height), ("name", age, height))
:
Name | Age | Height |
---|---|---|
Alex | 23 | 178 |
Noah | 34 | 189 |
Peter | 29 | 175 |
John | 41 | 185 |
Michelle | 35 | 165 |
- Print information for Peter.
- Print height of John.
- Print tuple converted into list (use
list
function)
Рішення
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 2.33Awesome!
Completion rate improved to 2.33
Tuples (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
Country | Area | Population |
---|---|---|
USA | 9629091 | 331002651 |
Canada | 9984670 | 37742154 |
Germany | 357114 | 83783942 |
Brazil | 8515767 | 212559417 |
India | 3166391 | 1380004385 |
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])
Swipe to start coding
Create two-dimensional tuple for people below in format (("name", age, height), ("name", age, height))
:
Name | Age | Height |
---|---|---|
Alex | 23 | 178 |
Noah | 34 | 189 |
Peter | 29 | 175 |
John | 41 | 185 |
Michelle | 35 | 165 |
- Print information for Peter.
- Print height of John.
- Print tuple converted into list (use
list
function)
Рішення
Дякуємо за ваш відгук!
single
Awesome!
Completion rate improved to 2.33
Tuples (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
Country | Area | Population |
---|---|---|
USA | 9629091 | 331002651 |
Canada | 9984670 | 37742154 |
Germany | 357114 | 83783942 |
Brazil | 8515767 | 212559417 |
India | 3166391 | 1380004385 |
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])
Swipe to start coding
Create two-dimensional tuple for people below in format (("name", age, height), ("name", age, height))
:
Name | Age | Height |
---|---|---|
Alex | 23 | 178 |
Noah | 34 | 189 |
Peter | 29 | 175 |
John | 41 | 185 |
Michelle | 35 | 165 |
- Print information for Peter.
- Print height of John.
- Print tuple converted into list (use
list
function)
Рішення
Дякуємо за ваш відгук!