[Tutor] Why is this printing None?

David Rock david at graniteweb.com
Wed Apr 15 10:15:52 EDT 2020


> On Apr 15, 2020, at 09:08, Cranky Frankie <cranky.frankie at gmail.com> wrote:
> 
> 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.

Ok, that clarifies and reinforces what I sent.  You are not doing the same thing that’s in that example.  In this section:

    Accessing Attributes
    You access the object's attributes using the dot operator with object. Class variable would be accessed using class name as follows −

    emp1.displayEmployee()
    emp2.displayEmployee()

note that it is calling emp1.displayEmployee() directly, NOT printing the result of it (i.e., print(emp1.displayEmployee())

By introducing the external print, your code has two print statements, not one: the print statement inside the method, and a second print statement outside the method.

— 
David Rock
david at graniteweb.com






More information about the Tutor mailing list