0
#!/usr/bin/env python

class SportsCar(object):

        def __init__(self,make,colour):
                self.make = make
                self.colour = colour
                self.horn = "BEEEEEEEEPPPPPPP"

        def honk(self):
                #now we can make some noise!
                print self.make,'  ',self.colour,'  ',self.horn
                print "Done "


mycar = SportsCar('Honda','silver')
#print mycar.make 
#print mycar.colour

print mycar.honk()


print "Good Bye!!"

The output of the above code is given below.

Honda    silver    BEEEEEEEEPPPPPPP
Done 
None
Good Bye!!

The first two lines of the output

Honda    silver    BEEEEEEEEPPPPPPP
Done

This is printed by mycar.honk().

I also understand the 4th line

Good Bye!!

I don't understand from where 'None' in the third line come from? Can someone please explain?

Also another related question

what is the difference between the declerations

class SportsCar:

and

class SportsCar(object):

I have been seeing both the declerations in different places.?

1
  • 2
    One question per question, please. Commented Apr 2, 2013 at 20:56

2 Answers 2

9

Functions always have a return value, None by default.

You are printing the return value of the .honk() method, which is the default None:

print mycar.honk()

You can just call mycar.honk() without the print statement. The method does it's own printing.

Sign up to request clarification or add additional context in comments.

1 Comment

0

You're not returning anything in your honk method, therefore it returns None by default.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.