+ 7
Python Range
numbers = list(range(3, 8)) print(numbers) print(range(20) == range(0, 20)) i can't understand this code ...... please help me,
3 Respostas
+ 2
range(start,stop) : returns sequence of integers from start (include)to stop (exclude)
range(3,8) produces 3,4,5,6,7
numbers=[3,4,5,6,7] as you are using range function inside list.
range(stop) : returns sequence of integers starting from 0 to stop-1
So range(20) is same as range(0,20)
bcoz both starts from 0 .and contains 20 elements.
print(range(20)== range(0,20)) returns True
+ 2
range(3,8) will produce a range object with values from 3 to 7 (one less than the end number) and to make a list of that object we use list function.
range(20) and range(0,20) are equal because python automatically takes the first argument to be 0 as default so range(30) is as same as range (0,30). hope it helps :)
+ 1
hi