Indentation level of `return`

Hello CC Moderator:

I have not used Count variable as most of the people here did (although I realize that it is simpler).

I have used the following to return the amount of numbers that are divisible by 10:

list_w_num_by_10 = []
def divisible_by_ten(nums):
  for number in nums:
    if number % 10 == 0:
      list_w_num_by_10.append(number)
      return
    len(list_w_num_by_10)

print(divisible_by_ten([20, 25, 30, 35, 40]))
print(list_w_num_by_10)
# prints: 
None
[20]

I do not understand why .append(number) is not adding number that satisfies the if statement into the list_w_num_by_10 list? It returns None even though there should be at least one number, 20, given the second print call.

Thank you for your insight!

5 Likes