0

I don't understand why i getting None in output of this code ?

class mobile:
    def __init__(self, name, brand):
        self.name = name
        self.brand = brand

    # def get_name(self):
    #     return self.name

class cpu(mobile):
    def get_name(self):
        print(self.name)


brand = cpu("Intel","Sony")
print(brand.get_name())

The output is :

Intel
None
Sir-Sorg
  • 175
  • 1
  • 2
  • 10
  • You're getting `None` because you are printing the return value of `brand.get_name()`, and you don't return a value from that function, in which case python treats the return value as `None`. – Nick Jun 18 '20 at 13:10
  • adding on to Nick's comment, instead of `print(self.name)` use `return self.name` – monte Jun 18 '20 at 13:11

0 Answers0