What are you referring to? It's if requested_toppings
it's going to check if the object is empty or not.
That’s why I’m having doubts on that… I thought IF statement must have either expression or condition then only it will execute
Yes… But then the IF statement doesn’t have any condition or expression?
the expression is implicit.
I see… So in this case, it can be written as if len (requested_toppings) == 0:?
yes, in this example where you're using a list.
And in what circumstances, we will use implicit expression?
For boolean: instead if if variable == True, you can use just if variable For int: instead of if variable != 0, you can just use if variable (any value different than zero, including negative) For str: instead of if variable != '', you can just if variable And so on. This also works for objects. Basically, if anything isn't None, it will trigger.
Yes I’m aware of For Boolean… Is it it’s just same as while True then the loops will loop infinitely without assign it to a variable?
Thanks for the explanation above 👆… Where can I read up in details on this?
Python docs, on the operators and expressions part, iirc
I couldn’t find it at https://docs.python.org/3/
A variable is an expression
Yes, more explicitly it checks the truthy value of the variable, in this case the truthy value of an empty list is false
Обсуждают сегодня