What is it printing 'None'?

I do not understand why it is printing “None”. Could someone explain??
(I am just learning, started maybe 3 week ago)

CODE
class Employee:
def init (self,name,age,salary,gender):
self.name = name
self.age = age
self.salary = salary
self.gender = gender

def show_details(self):
print("The name of the Employee is ", self.name)
print("The age of Employee is ", self.age)
print("The salary of Employee is ",self.salary)
print("The gender of Employee is ", self.gender)

e1 = Employee(‘Lori’, 37, 79000, ‘Female’)
e2 = Employee(‘Jon’, 40 , 40000, ‘Male’)

print(e1.show_details())
print(e2.show_details())

OUTPUT

The name of the Employee is Lori
The age of Employee is 37
The salary of Employee is 79000
The gender of Employee is Female
None
The name of the Employee is Jon
The age of Employee is 40
The salary of Employee is 40000
The gender of Employee is Male
None

When a function is exited without a return statement it implicitly returns None. When you do print(e1.show_details()) you are printing the return value of e1.show_details(), which is None. You don’t need to use print() here because the function already prints what you want.

Another way to code this would be to make show_details() build a string and return it, instead of printing inside the function. In that case, print(e1.show_details()) would work how you were expecting.

1 Like

Thank you Steven!