jskfan
asked on
Python Classes
Python Classes
in the example below, when I run the program, it shows what it is supposed to be printed to the screen, but it also add the word "None"
not sure why, though I followed the same example from a tutorial, but I did not see the program displaying the word "None" in that tutorial.
Any idea?
Thank you
in the example below, when I run the program, it shows what it is supposed to be printed to the screen, but it also add the word "None"
not sure why, though I followed the same example from a tutorial, but I did not see the program displaying the word "None" in that tutorial.
Any idea?
Thank you
That's because both the functions don't return anything and this is why it returns None when you call the function within the Print statement i.e. Print(point1.move())
ASKER
Print(point1.move()) Should print the word "Move", since it is calling the function Move
Print(point1.draw()) Should print the word "Draw", since it is calling the function Draw
Print(point1.draw()) Should print the word "Draw", since it is calling the function Draw
ASKER
I followed this youtube link below , you can forward it to 3 hours :26 minutes, the mentor did not get the None word when he ran the program..
https://www.youtube.com/watch?v=_uQrJ0TkZlc
https://www.youtube.com/watch?v=_uQrJ0TkZlc
Maybe you didn't pay attention to my post. As I said, since both the class methods don't Return anything and if you try to print them, they will return None other than executing the print statements defined in those Methods.
Try the following code and you will get an idea about how does it work...
Try the following code and you will get an idea about how does it work...
class Point:
def move(self):
print('Move')
return 'Move is returned by the move method'
def draw(self):
print('draw')
return 'Draw is returned by the draw method'
point1 = Point()
print(point1.move())
print(point1.draw())
ASKER
I see what you are saying, since the function does not return anything, it just runs the Print statement, so it returns None
I was just wondering why on the The video, there is no None returned.
I was just wondering why on the The video, there is no None returned.
At 3:26:00 in the video, the author is talking about the find_max(numbers) function and that function Returns the max number.
Are you sure that you are taking that function as a reference?
Are you sure that you are taking that function as a reference?
ASKER
sorry at 3:06:26
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Guys.
You're welcome!
Open in new window
The 'None' comes from the extra Print you have implemented...and because the method doesn't returns anything ...its 'None'