Explanation needed


def count_small(numbers):
    total = 0
    for n in numbers:
        if n < 10:
            total = total + 1
    return total

lost = [4, 8, 15, 16, 23, 42]
small = count_small(lost)
print small

Is the variable "small = count_small(lost)" calling the function count_small? Or what's happening here? I thought you can only call a function on a new line like count_small(lost) only, not in a variable. Thanks in advance.


Sort of. The expression on the right hand side is a function call. small is a cache of the return value or object assigned to it in the statement.

variable         expression
 small    =    count_small(lost)
   2  <= assign    <= return


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.