Explanation:
1. Creating the List
a, *b, c = [2, 4, 6, 8, 10]
The list contains:
2, 4, 6, 8, 10
2. Star Unpacking
a, *b, c = [2, 4, 6, 8, 10]
Python assigns the values like this:
a gets the first value → 2
c gets the last value → 10
*b collects all the remaining values → [4, 6, 8]
So:
a = 2
b = [4, 6, 8]
c = 10
3. Calculating a * c
a * c
Substitute the values:
2 * 10 = 20
4. Calculating sum(b)
sum(b)
Since:
b = [4, 6, 8]
Therefore:
4 + 6 + 8 = 18
5. Final Calculation
a * c - sum(b)
Substitute:
20 - 18 = 2
6. print()
print(a * c - sum(b))
So the final output is:
Final Output:
2

0 Comments:
Post a Comment