4
I’m having a question about how built-in any
python:
variavel = None
any([not variavel, variavel.get("chave1"), variavel.get("chave2")])
The way I see it, if the first item on the list was True
, the any
would already return True
and life that follows.
In the documentation itself, shows an example equivalent to what I believed would be the correct behavior.
However, I was testing in the terminal inside the Pycharm:
And apparently, even the first condition returning True
, He keeps checking the other items. I believe I’m making some poop, but I’ve tested in other environments and the result I find is the same. All environments are using Python 3.8.3.
the problem is not in the logical test.
None
has no method calledget
– Lucas
yes, but the doubt arose because this validation rolls within a context that expects a Dict. In the test, I made a request passing None and not {}, hoping that it was exactly the same behavior, after all, as it is inside a any, the first check would already return True, so it doesn’t matter if I use a Dict meodo or any other type, pq in teroria, nor would abter in the next element
– Mauro Martins Júnior
I don’t understand why the negatives are a pertinent question. The only problem with the question is error print instead of text.
– fernandosavio
yes.. I did not understand the negatives tbm, but ta good. the print was faltered, should have copied and pasted.
– Mauro Martins Júnior