0
Why this!? (3.0)
for python: nums= list(range(-10)) print(nums) output: [ ] Why its giving empty braces as output?
3 Answers
+ 6
nums= list(range(-10,0))
print(nums)
Try above.
Read below things and understand the solution.
Syntax : range(start, stop[, step])
It takes three arguments. Out of the three 2 arguments are optional. I.e., start and step are the optional arguments.
AĀ startĀ argument is a starting number of the sequence. i.e., lower limit. By default, it starts with 0 if not specified.
AĀ stopĀ argument is an upper limit. i.e., generate numbers up to this number, TheĀ range()Ā doesnāt include this number in the result.
TheĀ stepĀ is a difference between each number in the result. The default value of the step is 1Ā if not specified.
+ 1
range(-10) takes 0 as starting value and -10 as ending value. Since by default (when 'step' is not defined) start must be less than end, no numbers are generated.
In order to generate numbers you can:
1) invert start and end, as others suggested: range(-10, 0)
2) explicitly add a negative step: range(0,-10,-1)