class world:
def __init__(self, screen_size):
self.map = [[0 for col in range(500)] for row in range(500)]
self.generate()
def generate(self):
for x in range(0, len(self.map[0])):
for y in range(0, len(self.map)):
kind = random.randint(0, 100)
if kind <= 80:
self.map[x][y] = (random.randint(0, 255),random.randint(0, 255),random.randint(0, 255))
else:
self.map[x][y] = (random.randint(0, 255),random.randint(0, 255),random.randint(0, 255))
print self.map[50][50], self.map[-50][-50]
printing => (87, 92, 0) (31, 185, 156)
負值不超出範圍的可能性如何?它應該拋出IndexError。Python中,負值不在列表中的範圍內
負指數將列表向後索引('l [-1] == l [len(l) - 1]')。 – Blender