Learn
Passing a list to a function will store it in the argument (just like with a string or a number!)
def first_item(items): print items[0] numbers = [2, 7, 9] first_item(numbers)
- In the example above, we define a function called
first_item
. It has one argument calleditems
. - Inside the function, we
print
out the item stored at index zero ofitems
. - After the function, we create a new list called
numbers
. - Finally, we call the
first_item
function withnumbers
as its argument, which prints out2
.
Instructions
1.
Change line 2 so that list_function
returns only the item stored in index one of x
, rather than the entire x
list.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.