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)
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Vat dit hoofdstuk samen
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 2.33
Tuples (3/3)
Veeg om het menu te tonen
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)
Oplossing
Bedankt voor je feedback!
Awesome!
Completion rate improved to 2.33single