+ 1
Python - Multiplying an array for - 1
This empties array. Why? i=[1,2,3,4]*(-1) print(i)
2 Antworten
+ 6
When you multiply an integer n by a sequence python documentation says:
"Values of n less than 0 are treated as 0"
Hence you'll get an empty sequence of the same type. In your case an empty array.
+ 4
My guess would be that there's a condition in the loop that looks like:
if multiplicator > 0:
....
else:
return []
[1]*2 -> [1, 1]
[1]*1 -> [1]
[1]*0 -> []
[1]*-1 -> ... still []