Definition and test function for class Point. : Class Definition « Class « Python






Definition and test function for class Point.

 

class Point:
   def __init__( self, xValue = 0, yValue = 0 ):
      self.x = xValue
      self.y = yValue

   def __str__( self ):
      return "( %d, %d )" % ( self.x, self.y )      


point = Point( 72, 115 )

print "X coordinate is:", point.x
print "Y coordinate is:", point.y

point.x = 10
point.y = 10

print "The new location of point is:", point   

   
  








Related examples in the same category

1.Class Time with properties
2.Class Time with customized attribute access.
3.Simple class with slots
4.User-Defined Classes
5.NameTag class
6.Class instance value setting
7.Define a class