runtime
143 / 500
question 143 Advanced Functions & Recursion · easy

The first value that was provided

A customer's phone number can come from several places: their account, their last order, a delivery note. Each source gives None when it has no number. Write first_present(*values): return the first value that is not None, or None when every value is missing. Callers pass the sources as separate arguments, as many as they have.

Functionfirst_present(*values)
valuesany number of values, possibly none at all
Returnsthe first value that is not None; None if there is none
Rulesonly None counts as missing: 0, False and "" are real values and are returned
Examples
callfirst_present(None, '+44 20 7946 0958', '+1 202 555 0143')returns'+44 20 7946 0958'
callfirst_present('nora@fastmail.com', None)returns'nora@fastmail.com'
callfirst_present(None, None)returnsNone
callfirst_present()returnsNone

Loading your progress…

The first value that was provided — Python practice · Runtime