Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from point import Point >>> p1 = Point() >>> p1.x 0 # because of constructor! >>> p1.y 0 >>> p1.z # constructor does not assign z! Traceback (most recent call last): File "", line 1, in AttributeError: 'Point' object has no attribute 'z' >>> p1.translate (1, 5) >>> p1.x 1 >>> p1.y 5 >>> p2 = Point() >>> p2.x 0 >>> p2.y 0 >>> p1.x # p1 and p2 are independent! 1 >>> p1.distance (p2) 5.0990195135927845 >>> p1 = Point (2, 5) # good attempt, but... Traceback (most recent call last): File "", line 1, in TypeError: __init__() takes exactly 1 argument (3 given) >>> p1 = Point() >>> p1.translate (2, 5) >>> p1.x 2 >>> p1.y 5 >>> from point2 import Point >>> p1 = Point(2, 5) # new constructor >>> p1.x 2 >>> p1.y 5 >>> p2 = Point() # default parameters >>> p2.x 0 >>> p2.y 0 >>> p3 = Point (5) >>> p3.x 5 >>> p3.y 0 >>> p1 >>> print p1 >>> lst = [1,2,3] >>> lst2 = [1,2,3] >>> lst # looks better than our points [1, 2, 3] >>> lst2 [1, 2, 3] >>> lst == lst2 True >>> lst is lst2 # not the same object False >>> lst = [1,2,3] >>> lst2 = lst >>> lst == lst2 True >>> lst is lst2 True >>> p1 = Point(2,2) >>> p2 = Point(2,2) >>> p1 is p2 False >>> p1 == p2 # we expect this to be True, but... False >>> print p1 >>> def f1(): ... return 5 ... >>> f1() 5 >>> f2 = f1 >>> f2() 5 >>> Point >>> junk = Point >>> from counter import Counter >>> c1 = Counter() >>> c1.instances 1 >>> c2 = Counter() >>> c2.instances 2 >>> c1.instances 2 >>> c3 = Counter() >>> c1.instances 3 >>> Counter.instances 3 >>> Counter.instances = 0 >>> c1.instances 0 >>> >>> p1 = Point() >>> print p1 >>> from point3 import Point >>> a = Point(3, 4) >>> print a (3, 4) >>> str(a) '(3, 4)' >>> a >>> lst = [1,2,3] >>> print lst [1, 2, 3] >>> lst [1, 2, 3] >>> a >>> p1 = Point(2, 2) >>> p2 = Point (2, 2) >>> p1 == p2 False >>> p1 < p2 True >>> from point4 import Point >>> p1 = Point(2, 2) >>> p2 = Point (2, 2) >>> p1 == p2 # with __cmp__ True >>> p1 is p2 False >>> len(p1) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'Point' has no len()