List Indices

Description

If we want to pull a specific item from a list, we use the lists name and the item's index. The index of the list runs from 0 to 1 less than the lists length.

Sage Cell

Code

A = [ 2, 3, 5, 7, 11 ]
print A[0]
print A[4]

Options

Accessing the Last Members of a List

By calling a negative index, you can access a member of a list counted from the back instead of the front. Negative indices for a list A of length n go from -1 to -n, where A[-1] is the last item in the list and A[-n] is the first.

Code

A = [ 2, 3, 5, 7, 11 ]
print A[-1]
print A[-5]

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 23 Mar 2019 01:02

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License