Multiplying a tuple by a scalar

后端 未结 12 901
忘了有多久
忘了有多久 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:05

    The pythonic way would be using a list comprehension:

    y = tuple([z * 10 for z in img.size])
    

    Another way could be:

    y = tuple(map((10).__mul__, img.size))
    

提交回复
热议问题