Python "class" question

0 Sako Bu · April 5, 2015
Hello,

Here is the screen shot of the code and the question is the following - when I call the second method (saying) why is the result:

Hello Bob
None
Hello Tony
None

Why the "None"?

Thanks in advance!

/images/forum/upload/2015-04-04/120978130003c58c58b7a223b9d82eca.png

Post a Reply

Replies

Oldest  Newest  Rating
0 The BM · April 5, 2015
Do something like this 

class className:
def createName(self,name):
self.name = name

def displayName(self):
return self.name

def saying(self):
return str(("Hello %s" % self.name))

first = className()

first.createName('Bob')

print(first.displayName())

print(first.saying())


the problem is that your def saying just already prints something and if you try to print that , then its none because print ain't a variable typ i guess.
And print without the brackets cause your are proberly using 2.7 or so..
  • 1

Python

107,017 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator