Reputation: 4171
I read some python codes like follows:
color = (1.0,)*4
I couldn't figure out what does it mean? (1.0,) means some tuple, but what does it mean by multiplying 4 here?
Upvotes: 0
Views: 115
Reputation: 1123930
You create a new tuple with 4 times the same referenced value.
>>> (1.0,) * 4
(1.0, 1.0, 1.0, 1.0)
See the Sequence types reference
s * n, n * s
n
shallow copies ofs
concatenated
Note that it's the exact same value that is reused; you see this when you use a mutable value:
>>> lst = []
>>> tup = (lst,) * 4
>>> tup[0] is lst
True
>>> all(i is lst for i in tup)
True
Upvotes: 3