Link to home
Start Free TrialLog in
Avatar of jskfan
jskfanFlag for Cyprus

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

User generated image
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Here is how you should have implement the class
class Point:
    def MoveT(self):
        print('Move')

    def DrawT(self):
        print('Draw')

point1 = Point()
point1.MoveT()
point1.DrawT()

Open in new window

The 'None' comes from the extra Print you have implemented...and because the method doesn't returns anything ...its 'None'
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())
Avatar of jskfan

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
Avatar of jskfan

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
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...

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())

Open in new window

Avatar of jskfan

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.
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?
If you go to 3:26:25 (around) you will see that actually he returns
User generated image
Avatar of jskfan

ASKER

sorry at 3:06:26
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jskfan

ASKER

Thank you Guys.
You're welcome!