0

I was playing around with a tutorial from a website. And wondering why the below code prints

Name :  Gerhardt , Salary:  500
None

The first line I'm alright with. But I do not know why it prints None?

class Employee:
    'Common base class for all employees'
    empCount = 0

    def __init__(self, name, salary):
        self.name = name
        self.salary = salary
        Employee.empCount += 1

    def displayCount(self):
        print ("Total Employee %d" % Employee.empCount)

    def displayEmployee(self):
        print ("Name : ", self.name,  ", Salary: ", self.salary)

    def changeSalary(self, n):
        self.salary = n;

class ChiefEmployee(Employee):

    def __init__(self, name, salary):
        Employee.__init__(self, name, salary)


emp3 = ChiefEmployee("Gerhardt", 500)

print(emp3.displayEmployee())
PushALU
  • 257
  • 1
  • 3
  • 15
  • 1
    Briefly: because you're printing the returned value, which is `None`. Either have the function `return` the desired value instead of printing it directly, or call the function without wrapping it in a second `print()`. – TigerhawkT3 Mar 30 '16 at 05:04
  • Ahh silly mistake of me. Thanks.! – PushALU Mar 30 '16 at 05:08

0 Answers0