99% of devs make this Python mistake

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

why don't we use list comprehention for this example instead?
It's faster and uses only one variable

def
return [n for n in numbers if n and 100 > n > 0 and n % 2 == 0]

rndargis
Автор

You are aware that you can just use the „and” operator to put multiple conditions in one if?

Also, in python it doesn’t matter, but generally creating extra variables like that is bad for performance

monabuu
Автор

What is inherently wrong with writing nested if statements?

theprocrastinationnation
Автор

I dunno, the stacked if statements were plenty readable. I don't see how the second variant is objectively better.

In fact, I'd argue the stack of IF is more expandable... since I can easily add else to each level to handle them all individually

DragongeekAndCo
Автор

Python also can do 0 <= number <= 100?
Im not a python guy tho xd

Ukyuu
join shbcf.ru