+ 4
[Solved] Why is the output of the following code [4,3]?
a, b, *c, d = [1,4,3,4,3] print(c[::-1])
2 Answers
+ 6
AFAIK:
This code assigns following values to variables:
a = 1
b = 4
c = [3, 4]
d = 3
There are two numbers in "c" because it has a "*" symbol, so it receives everything that remained unused.
And then we print c[::-1]. [::-1] is a list slice. It accepts three parameters: from, to and step. Here from and to are omitted, so the whole list is used. And step is -1, so it will print all elements from last to first.
Output: [4, 3]
+ 4
Artem Really great explanation..... Thank you. My main doubt was in '*c' part, which is now clear. Thanks again!