[Tutor] class problem

Alan Gauld alan.gauld at btinternet.com
Sat Sep 18 17:11:36 CEST 2010


"Roelof Wobben" <rwobben at hotmail.com> wrote

> Create and print a Point object, and then use id to print the
> object’s unique identifier. Translate the hexadecimal form into 
> decimal and
> confirm that they match.

I initially had no idea what hexadecimal form the text is talking 
about.
id returns a decimal form... This is a badly worded assignment.

> class Point:
>     def __init__(self, x=0, y=0):
>         self.x = x
>         self.y = y
>
> P=(Point)
> a=0
> b=0

The two a,b assigments are seemingly pointless?

> a=id(P)
> print a
> print b
> print P

Why do you want to print b which will  be zero?

However your print P gave me a clue to what the assignment is about.
When you print the object it gives you a hex value     I think they 
want
you to extract that value and convert it to decimal to see if its the 
same
as the value id() gives you.
At least that's the only sane thing I can think it means!

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list