A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://holypython.com/beginner-python-exercises/exercise-6-python-lists/ below:

Improve your Python skills with Exercise 6: Lists

  Python List Exercises

In this page you can find interactive exercises to practice Python’s

List

data structure and its methods. If you’d like to practice

List Comprehensions

, a more advanced Python

List

concept, 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 1

list[index] Correct syntax to call a list’s element is brackets with the index number inside next to the list’s name:

Hint 2

List index starts with zero.

Solution
answer_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 1

Second element is index 1: [1]

Solution
print(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 1

last element is easiest to print with reverse indexing, which starts with -1.

Solution
answer_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