[Tutor] Why is this printing None?

Mats Wichmann mats at wichmann.us
Wed Apr 15 09:37:01 EDT 2020


On 4/15/20 7:24 AM, Cranky Frankie wrote:
> I have this simple class in Python 3.8. When I run this in IDLE or at the
> command prompt the word None gets printed after the employee name. Why?
> 
> class Employee:
> 
>     def __init__ (self, name):
>         self.name = name
> 
>     def displayEmployee(self):
>         print("Name : ", self.name)
> 
> if __name__ == '__main__':
>     emp1 = Employee('Zara')
>     print(emp1.displayEmployee())

Your last line here prints the value returned by displayEmployee().

What is that method returning?

Hint: if a function/method does not explicitly return something via a
return statement, it returns None.




More information about the Tutor mailing list