I want to create a class for numbers that takes ints, tuples, sets or lists. I tried using little knowledge I had of oop in python and this is what I could come up with as an __init__
method. But I don't think this is the way it is meant to be written. Also I can't iterate over my objects and when I print an object, I just get the object id. Do I have to write another method to be able to print it?
class Numbers():
def __init__(self, num):
assert isinstance(num, int) or isinstance(num, list) or isinstance(num, set) or isinstance(num, tuple), 'invalid numbers'
if isinstance(num, int):
self.num = int(num)
elif isinstance(num, list):
self.num = list(num)
elif isinstance(num, tuple):
self.num = tuple(num)
elif isinstance(num, set):
self.num = set(num)
>>>b = Numbers([1,2,3,4,5]) >>>b <__main__.Numbers object at 0x000001DF24F25250>