Answer the question
In order to leave comments, you need to log in
How to create a class with an indefinite number of variables?
Good time of the day.
I have this problem: you need to create a class - Vector, which can be of any dimension. And for him a couple of methods. I have a hitch with the initiation, and the presentation in the text version.
a = Vector(1,2,3)
str(a) == '(1,2,3)' #так должень быть представлен
class Vector:
def __init__(self, *args):
for arg in args:
setattr(self, str(arg), arg)
def __str__(self):
return "({})".format(",".join(args))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question