+ 1

Range() & len () question

Why the output is 0? a = range(5) b = [x for x in a if x >= 5] print(len(b))

19th Jun 2018, 8:17 PM
Dolan
Dolan - avatar
3 Antworten
+ 13
Because the last number 'a' contains is 4 and the comprehension requires it to be over 5.
19th Jun 2018, 8:40 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
Valen.H. ~ if only print (a), the output is range (0, 5). does this take into account as only two arguments (0 and 5)? or as a range of 5, (0,1,2,3,4)!?
19th Jun 2018, 9:14 PM
Dolan
Dolan - avatar