def first_even(items):
""" (list of int) -> int
Return the first even number from items. Return -1 if items contains no even numbers.
>>> first_even([5, 8, 3, 2])
8
>>> first_even([7, 1])
-1
"""
counter = 0
for item in items:
counter = counter + 1
if item % 2 == 0:
return item
elif counter == len(items):
return -1
詳細詳細詳細詳細詳細當空列表作爲參數傳遞時,如何避免返回None類型?
「詳情詳情詳情詳情詳情」?您是否期待「Code Code Answer Explanation Code」的答案? – TigerhawkT3