08. Check for Understanding: Lists

Check for Understanding

Data types and data structures are tricky but important concepts to master! Let's pause and make sure you understand the distinction between them.

Which of the following statements about data types and data structures are true? Select all that apply.

SOLUTION:
  • Data structures are containers that can include different data types.
  • A list is an example of a data structure.
  • All data structures are data types.

Which of the following are properties of lists? Select all that apply.

SOLUTION:
  • Mutable
  • Ordered

The next two quizzes will test your understanding of indexing and slicing lists. I encourage you to try answering these questions without testing them in code first. However, if you would like to experiment with code after your first try, there is a code editor at the bottom of this page for you to do so.

QUIZ QUESTION::

Choose the correct syntax to index each of the following elements from a list, arr.

ANSWER CHOICES:



Element

Indexing Syntax

arr[-2]

arr[-3]

arr[4]

arr[3]

arr[len(arr)]

arr[len(arr) - 1]

arr[1]

arr[0]

SOLUTION:

Element

Indexing Syntax

arr[-2]

arr[3]

arr[len(arr) - 1]

arr[0]

QUIZ QUESTION::

Choose the correct syntax to slice each of the following elements from the list: arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g']

ANSWER CHOICES:



Elements

Slicing Syntax

arr[4:]

arr[3:7]

arr[:3]

arr[2:6]

arr[:2]

arr[0:2]

arr[4:6]

arr[2:5]

SOLUTION:

Elements

Slicing Syntax

arr[4:]

arr[:3]

arr[2:6]

Start Quiz:

arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
print(arr[0])