In this page you can find interactive exercises to practice Python’s
Listdata structure and its methods. If you’d like to practice
List Comprehensions, a more advanced Python
Listconcept, you can click
here. Exercises aim to gradually increase in difficulty. So, let’s start.
Exercise 6-a: Calling Elements of a Python List (Index 0)Assign the first element of the list to answer_1 on line 2
Hint 1list[index] Correct syntax to call a list’s element is brackets with the index number inside next to the list’s name:
Hint 2List index starts with zero.
Solutionanswer_1 = lst[0]Exercise 6-b: Calling List Elements and Indexing
And let’s print the second element directly inside print function.
This time print the second element of the list directly on line 3. You should get 100.
Hint 1Second element is index 1: [1]
Solutionprint(lst[1])Exercise 6-c: Calling List Elements (Negative Index)
And the last element.
Print the last element of the list through variable answer_1.
Hint 1last element is easiest to print with reverse indexing, which starts with -1.
Solutionanswer_1=lst[-1]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4