Multiplying a tuple by a scalar

后端 未结 12 887
忘了有多久
忘了有多久 2020-12-14 14:48

I have the following code:

print(img.size)
print(10 * img.size)

This will print:

(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70,          


        
12条回答
  •  隐瞒了意图╮
    2020-12-14 15:16

    There is probably a simpler way than this, but

    print map(lambda x: 10*x, img.size)
    

    Will do nearly what you want, although it prints as a list rather than a tuple. Wrap the map call inside tuple(map...) if you want it to print as a tuple (parentheses rather than square brackets).

提交回复
热议问题