.len() and saving to a variable

I’m working on the Len’s Slice project. I am stuck on step 4 ( Find the length of the toppings list and store it in a variable called num_pizzas .)
I have tried everything I can think of to make this code segment work:
len(toppings) = num_pizzas
It only returns the error

“File “script.py”, line 6
len(toppings) = num_pizzas
SyntaxError: can’t assign to function call”

I tried adding the period, doing toppings.len, everything, but nothing works.

Sometimes the wording of the steps is a bit confusing (or at least I’ve found that to be true).

.len() is a built in function and a parameter is passed through it.

Did you try switching around your variable definition?


num_pizzas = len(toppings)
1 Like

Ah, I didn’t realize there was an order you had to do those steps in!
Thanks for the help, I’ll try to remember that with functions!

1 Like

Also, in your terminal window, you can type:


which will result in:

Help on built-in function len in module builtins:

len(obj, /)
    Return the number of items in a container.

*You can use help() to get the definitions of any function in Python.

Or consult the Python documentation:


You’ve defined “toppings” and you’re passing that through the len() function:

toppings= ["pepperoni", "pineapple","cheese",

prices = [2, 6, 1, 3, 2, 7, 2]

num_two_dollar_slices = prices.count(2)


num_pizzas = len(toppings)