+ 2
I can't understand this question! Please help!!!
What is the output of this code? x = [2,4] x = x * 3 print(x[3]) I know that the answer is 4, because I paid bits, but I don't understand HOW! Please help.
1 Answer
+ 4
Multiplying a list duplicates the items with the order. You can check it by print it out.
print(x * 3) #output [2, 4, 2, 4, 2, 4]
Try multiplying by different numbers probably make it more clear.
x * 2 gives [2, 4, 2, 4]
x * 4 gives [2, 4, 2, 4, 2, 4, 2, 4]
If you know the entire list, it is clear what x[3] is.