[Tutor] Why is this printing None?

David bouncingcats at gmail.com
Wed Apr 15 09:36:07 EDT 2020


On Wed, 15 Apr 2020 at 23:25, Cranky Frankie <cranky.frankie at gmail.com> 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())

emp1.displayEmployee()
has a return value of None,
so
print(emp1.displayEmployee())
is the same as
print(None)

Do you need to call print() twice?


More information about the Tutor mailing list