+ 1

a small doubt in MAgical Methods

return self.cont[index + random.randint(-1, 1)] why don't we use VagueList instead of self.cont ,,. i mean return VagueList[index + random.randint(-1, 1)] ,,,. As we used previously in Vector2D Example ---> Please look down at two examples @Return Values Example1:import random class VagueList: def __init__(self, cont): self.cont = cont def __getitem__(self, index): return self.cont[index + random.randint(-1, 1)] def __len__(self): return random.randint(0, len(self.cont)*2) vague_list = VagueList(["A", "B", "C", "D", "E"]) print(len(vague_list)) print(len(vague_list)) print(vague_list[2]) print(vague_list[2]) Example2: class Vector2D: def __init__(self, x, y): self.x = x self.y = y def __add__(self, other): return Vector2D(self.x + other.x, self.y + other.y) first = Vector2D(5, 7) second = Vector2D(3, 9) result = first + second print(result.x) print(result.y)

25th Apr 2017, 3:01 AM
sandeep
sandeep - avatar
1 ответ
+ 4
Nice work.
10th May 2017, 6:39 PM
devbyemil
devbyemil - avatar