Explanation:
๐น Step 1: Create Generator
x = (i for i in range(4))
A generator object is created.
Generator values:
0,1,2,3
⚠️ Important:
Generator gives values one by one when consumed.
๐น Step 2: Start Unpacking
a,b,*c = x
Python starts unpacking values from generator.
๐น Step 3: Assign First Value to a
First value:
0
So:
a = 0
๐น Step 4: Assign Second Value to b
Next value:
1
So:
b = 1
๐น Step 5: Remaining Values Go to *c
Remaining generator values:
2,3
Star unpacking:
*c
collects remaining values into LIST ๐
So:
c = [2,3]
⚠️ Important:
Even though source is generator,
star unpacking always creates LIST.
๐น Step 6: Execute print(c)
print(c)
So output becomes:
[2,3]
๐ฅ Final Output
[2, 3]

0 Comments:
Post a Comment