If you are using python2.x, then where you think you are calling print like a function, you are really printing a tuple, using the print keyword...
print(1,2,3)
print (1,2,3)
In python3, you have to do it like a function call print(1,2,3)
.
So in your case, in python2.x, what you are printing is a tuple of values. Tuple tuple object will be converted to a string, and each value in the tuple will have its representation printed. When you print them as this: print "Point",p1
, then each item will be converted to a string and printed.
print str(p1)
# Point x: 1, Point y: 2
print repr(p1)
# <__main__.Point instance at 0x00D96F80>
You would actually probably want to use __repr__
instead of __str__
:
class Point():
def __init__(self,x,y):
self.x = x
self.y = y
def __repr__(self):
return "Point x: {0}, Point y: {1}".format(self.x, self.y)