Purpose of using pass in example Python function

Viewed 35

I'm currently taking a Python course on Udemy and I'm at the point where I'm learning to create my own functions. In the section dealing with functions and tuple unpacking, I was shown the example function:

def employee_check(work_hours):

current_max = 0
employee_of_month = ''

for employee,hours in work_hours:
    if hours > current_max:
      current_max = hours
      employee_of_month = employee
    else:
      pass

#Return
return(employee_of_month,current_max)

My question is simply what is the point of putting pass as an else statement in this specific example? Messing around, it seems to still operate properly whenever I take it out, is there a use that I'm not aware of or is it just a good habit to get into when creating functions?

EDIT: The purpose of the function being to designate the employee of the month based on total hours worked

1 Answers

Good habit, easier readability, faster to understand. And it means that you deliberately wanted to skip doing something on the else condition.

Alternatively, you could consider (or someone who is reading your code) that you missed / ignored what would happen in the else condition.

A good practice is to think what would future you / other person would think when they see your code. Also, most courses encourage these good practices.

Related