Skip to content

Latest commit

 

History

History
54 lines (32 loc) · 1.96 KB

list-exercises.md

File metadata and controls

54 lines (32 loc) · 1.96 KB

List Access

Complete the following exercises by editing this file directly on GitHub, using the little pen symbol at the top right of the text box on this page.

Use the Python interpreter to confirm your answers as you go. After writing each answer, make a commit by scrolling down, writing a commit message, and pressing the green button.

Use the following list for the questions:

my_list = [1, 2, "kitten", 4, "five"]

Note that the little quote marks you see around this line when editing make it look like code on the original page! Use them for your answers when the answer is code.

How would I access the third element in the list?

  • Your answer here (remember to commit after editing this line to contain your answer!)

How would I access the element at index 3?

  • Your answer here (remember to commit after editing this line to contain your answer!)

What would I get if I did my_list[1]?

  • Your answer here (remember to commit after editing this line to contain your answer!)

What are three ways I could access the last element of the list?

(HINT: Look up the len method for Python lists.)

  • Your answer here (remember to commit after editing this line to contain your answer!)

How would I find the length of the list?

  • Your answer here (remember to commit after editing this line to contain your answer!)

Use the list below to complete the following table (the first one is done for you):

my_list = [1, 2, “kitten”, 4, “five”, 6, 7]

access method value
my_list[0] 1
my_list[1:3]
my_list[1:6]
my_list[1:10]
my_list[-1]
my_list[-1:-3]
my_list[-3:-1]

(remember to commit after editing this table to contain your answer, and removing this line!)

Review Time!

Now call over one of the instructors or the TA to come look through your commit history!

Once they have, go back to the main page of the repository by clicking the hackbright-intro-lists-and-io link at the top of the page.