0

I did create a class.

class Type:
    p = []
    r = []
    s = []

Then, in the main I use it 3 times. The first one :

Short = Type()

then I use the list to append some data in it. The second time I declare it

Avreage = Type()

But.. at that moment, evrey data that is in Short jump into Average. Like if when a right Short.p[0] = 2, it write it in the class itself.. What do I have to do to solve this ?

Vivek Sable
  • 9,938
  • 3
  • 40
  • 56

1 Answers1

0
>>> class Type:
...     p = []
...     r = []
...     s = []
...

Here variable 'p', r and s are class variable.

Class Variable Definition: Variables declared inside the class definition, but not inside a method are class or static variables, which can me access by class instance i.e. object or by class name (outside of class).

e.g.

>>> a = Type()
>>> a.p
[]
>>> a.p.append(3)
>>> a.p
[3]
>>> b = Type()
>>> b.p
[3]
>>> Type.p
[3]
>>> 
Vivek Sable
  • 9,938
  • 3
  • 40
  • 56