[Tutor] asigning class variables
Kent Johnson
kent37 at tds.net
Sun Feb 14 04:41:59 CET 2010
On Sat, Feb 13, 2010 at 8:08 PM, the kids <the7hansons at msn.com> wrote:
> Hi, my name is John Paul.
>
> I was trying to define a class but I can't make it asign particular objects
> particular variables at their creation. Please help.
It would help to see some details of what you are trying to do. It
sounds like you want an __init__() method in your class:
In [1]: class Data(object):
...: def __init__(self, a, b):
...: self.a = a
...: self.b = b
In [2]: d = Data(1, 2)
In [3]: d.a
Out[3]: 1
In [4]: d.b
Out[4]: 2
In [5]: dd = Data(42, 57)
In [6]: dd.a, dd.b
Out[6]: (42, 57)
Kent
More information about the Tutor
mailing list