CodingNeed.

3 · Work with collections · 8 MIN

Keep an ordered list

Arrays store values in order, starting at index zero.

A list holds ordered values. Index zero is the first item and len gives the number of items. An out-of-range index raises IndexError. None represents the absence of a value and becomes null in these JSON test results.

A row of numbered lockers starts at locker 0 in JavaScript.

Read the example

names = ["Ada", "Lin", "Grace"]
print(names[0])
print(len(names))
Check the expected output
Ada
3

Your challenge

Return the first item of the input list. Return None if the list is empty.

Common trap

Check an empty list before reading index zero.

Next lesson: Repeat with a loop →

Essential cookies keep your account signed in. Optional analytics is not configured on this site. Your choice does not affect access to lessons.

Read the Privacy Policy. You can change this choice in the footer.