Why is the output [], and not an error? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

Why is the output [], and not an error?

numbers = list(range(20,5, 2)) print(numbers)

29th Aug 2020, 7:15 PM
иван
иван - avatar
7 ответов
+ 7
uuufffffff finally the answer is: Guido decided so. Guido invented Python.
29th Aug 2020, 7:24 PM
Oma Falk
Oma Falk - avatar
+ 4
Oma Falk well, at least found out who invented Python😄
29th Aug 2020, 7:33 PM
иван
иван - avatar
+ 4
иван but you are right it could be handled as error. Simply a question of which way is better.
29th Aug 2020, 7:48 PM
Oma Falk
Oma Falk - avatar
+ 3
list() will return empty list.. You code also return empty list. So not error since assigning empty list.. And also since there no syntax error, it won't be raise error.. There is only logical error of programmer in case if it is wrong..
29th Aug 2020, 7:23 PM
Jayakrishna 🇮🇳
+ 2
Because the third parameter in the range accepts an integer, and the range here will start from 20 and ends at 5, but step count is +ve 2, therefore it cannot find any value so it returns a blank list
29th Aug 2020, 7:26 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
Tamy 😝 I know the question was different ..
30th Aug 2020, 11:21 AM
иван
иван - avatar
0
If you want to start the range in 20 and finish it in 5, your step should be -2 instead of +2.
30th Aug 2020, 3:39 AM
Tamara Raquel da Silva
Tamara Raquel da Silva - avatar