CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List
Python Code Walkthrough #23

Returning Early From A Loop

mediumFunctions

📄 Code

Read carefully — what does this print?
1def first_negative(values: list[int]) -> int:
2 for value in values:
3 if value < 0:
4 return value
5 return 0
6 
7print(first_negative([3, -2, -8]))
8print(first_negative([1, 2]))
9print(first_negative([-5]))

🎯 Your Answer