How can I define a python attribute as a class? I want to define a Python class that instantiate the objects that are list type. I can do that using __init__ and a class method, but I'm looking for a way to avoid using a method.
Second question is that I'm wondering if I can define a class with a constructor that accept variable arguments (e.g. to use this class to instantiate objects with different No of indexes ([4,5,6] and [1,2,3,4,7]).
I've copied my code below.
Thanks for your help :)
class SuperList(list):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
def My_list(self):
return [self.a, self.b, self.c]
obj1 = SuperList(1, 2, 3)
List1 = obj1.My_list()
List1.append(8)
print(List1)
<class 'list>and can be useful for creating custom methods without overwriting inbuilt class.