Reputation: 65
I have four variables: x
, y
, height
, and width
(all integers or doubles). I want to multiple all four by some number, a
(also an integer or double). It's possible to write
x *= a
y *= a
height *= a
width *= a
Is there a more concise, one-line version of this?
Upvotes: 0
Views: 1327
Reputation: 15872
You can invoke __mul__
magic with map
(this is an ugly, added it for sake of variation):
>>> x,y,height,width = map(a.__mul__,(x,y,height,width))
Upvotes: 0
Reputation: 5785
Try this one, no need to write a
four times
>>> for i in [x, y, height, width]:
print(a*i)
Upvotes: 0
Reputation: 2231
You can do with unpacking:
x, y, height, width = x*a, y*a, height*a, width*a
Upvotes: 4