#๐ Which is faster (or preferred on work groups)?
14 messages ยท Page 1 of 1 (latest)
@sour goblet
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
The second if good if you have a lot of nested ifs
I'd expect them to be so similar it doesn't matter. Do what is most readable.
If you have only a few ifs, the first one is more readable
They are probably as fast
(You could try to measure it tho)
Fundamentally, it depends on the nature of something, and the amount of the second code
Isnโt something always a bool value?
And why the amount of the second code is relevant?
the first form can simplify the following code and reduce nesting. It's appropriate for filtering out exceptional conditions or special cases. You can deal with them and then return early, and then the rest of your code knows that the input data is in a good state and it can focus on that happy path.
Just knowing something evaluates to (or can be interpreted as!) a boolean, doesn't explain its purpose.
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.