Explain in detail ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Explain in detail ?

list = [1,2,3,4] a,*b,c = list print(list) print(a) print(b) print(c)

3rd May 2021, 5:17 PM
🇮🇳Akash Æ
🇮🇳Akash Æ - avatar
2 Answers
+ 2
The key here is in the line a, *b, c = list Here, a takes the first element (1), c takes the last element (4), and, because b has the little * before it, it takes everything else that lies in between, so it is [2, 3] in this case. See some other examples here. lst = [1,2,3,4] a,b,*c = lst # a = 1, b = 2, c = [3,4] *a,b,c = lst # a = [1,2], b = 3, c = 4 a,b,c,d = lst # a = 1, b = 2, c = 3, d = 4 a, *b = lst # a = 1, b = [2,3,4] Hope this helps.
3rd May 2021, 6:08 PM
Russ
Russ - avatar
0
Russ Thanks sir ...
4th May 2021, 2:18 AM
🇮🇳Akash Æ
🇮🇳Akash Æ - avatar