Back to Freecodecamp

Step 3

curriculum/challenges/english/blocks/learn-lambda-functions-by-building-an-expense-tracker/66694fc4bba24f33ca01fa5b.md

latest1.3 KB
Original Source

--description--

Python has a handful of list methods. Such as methods for adding or removing list items.

You can add an item to the end of a list using the append() method. For example:

py
example_list = [4, 5, 6]

example_list.append(7)

example_list now is [4, 5, 6, 7].

Try to use the append() method to add 3 to my_list. Then print the list.

--hints--

The last element of my_list should be 3.

js
({
    test: () => runPython(`
        assert my_list[2] == 3, "my_list[2] is not 3"
    `)
})

my_list should have a length of 3.

js
({
    test: () => runPython(`
        assert len(my_list) == 3, "my_list doesn't have three elements"
    `)
})

You should not change the list declaration.

js
({
    test: () => runPython(`
        assert _Node(_code).find_variable('my_list').is_equivalent("my_list = [1, 2]")
    `)
})

You should print the list.

js
({
    test: () => runPython(`
    calls = _Node(_code).find_calls("print")
    assert any(call.is_equivalent('print(my_list)') for call in calls)
    `)
})

You should print the list after using append().

js
({
    test: () => runPython(`
    assert _Node(_code).is_ordered('my_list.append(3)', 'print(my_list)')
    `)
})

--seed--

--seed-contents--

py
--fcc-editable-region--
my_list = [1, 2]
--fcc-editable-region--