Multiplying a tuple by a scalar

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

    You are trying to apply the function on Tuple as a whole. You need to apply it on individual elements and return a new tuple.

    newTuple = tuple([10*x for x in oldTuple])
    

    Remember you cannot change a Tuple.

提交回复
热议问题