[Tutor] Why is this printing None?

Cranky Frankie cranky.frankie at gmail.com
Wed Apr 15 10:08:13 EDT 2020


It prints the word Zara like it should, then the word None on the next line
which it shouldn't. I got the example from:

https://www.tutorialspoint.com/python/python_classes_objects.htm

When they show the results, the word None is not output.

I don't know why this is happening.
Frank L. "Cranky Frankie" Palmeri, Risible Riding Raconteur & Writer
WORK Hard - PLAY Hard - READ Hard - THINK Hard


On Wed, Apr 15, 2020 at 9:37 AM Mats Wichmann <mats at wichmann.us> wrote:

> 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.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list