+ 1

Confused, please help

Why does this: a, b, c, d, *e, f, g = range(20) print(len(e)) print out 14?

3rd Apr 2021, 6:21 PM
Tabetha Ridgway
Tabetha Ridgway - avatar
2 odpowiedzi
+ 7
Range(20) Return 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 a = 0 b = 1 c = 2 d = 3 e = 4-17 numbers f = 18 g = 19 len(e) will return how many numbers in 4-17 they are 14😄 Hope you understand happy coding!
3rd Apr 2021, 6:32 PM
Սոֆի
+ 1
As far as I know For range based loops if we assign corresponding var, it should take up the whole value. i.e. for eg when range is 20 and 6 variables it takes 6 values of one. And the remaining 20-6=14 is taken up by *e So len(e)=14
3rd Apr 2021, 6:28 PM
Aditya
Aditya - avatar