Back to Freecodecamp

Step 5

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

latest1.4 KB
Original Source

--description--

Python lists are mutable which means that the value of the list items can be changed. You can change the value of an element using the bracket notation.

py
example_list = [4, 5, 6, 7]
example_list[1] = 'oh'

This will make example_list have value of [4, 'oh', 6, 7].

Change the first element of my_list to 0, then print the list to check the value.

--hints--

Do not change the list declaration.

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

The first element of my_list should be 0.

js
({
    test: () => runPython(`
        assert my_list[0] == 0
    `)
})

You should change the first element using my_list[0] = 0.

js
({
    test: () => runPython(`
    assert _Node(_code).has_stmt("my_list[0] = 0")
    `)
})

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 changing the first element.

js
({
    test: () => runPython(`
    assert _Node(_code).is_ordered("my_list[0] = 0", "print(my_list)")
    `)
})

--seed--

--seed-contents--

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

my_list.append(3)
print(my_list)

print(my_list[0])

--fcc-editable-region--