3 ms·
def wrap_around(self): """Change the position of the bubble to toroidally "wrap around" if it goes off one edge of the map."""
by ralph 14y ago
def wrap_around(self):
"""Change the position of the bubble to toroidally
"wrap around" if it goes off one edge of the
map."""
if self.pos.x < 0: self.pos.x += 1
if self.pos.y < 0: self.pos.y += 1
if self.pos.x > 1: self.pos.x -= 1
if self.pos.y > 1: self.pos.y -= 1
Why isn't else used? In addition to efficiency it tells the reader that the author expects at most one of x++ or x-- to happen.