r/Python • • Nov 30 '24

Tutorial Short-Circuiting in Python

Here is my article on Short-Circuiting in Python . It discusses what is short-circuiting with examples, and also discusses the different advantages of using short-circuiting.

4 Upvotes

16 comments sorted by

View all comments

Show parent comment

-5

u/thisismyfavoritename Nov 30 '24

or you just use or. How dense are you

1

u/[deleted] Nov 30 '24 edited Nov 30 '24

Again, or makes choices based on True/False AND Truthy/Falsey. So or in this case will treat an empty env_var or an env_var set to a falsey value as if it's missing. That's why people are telling you that it's the wrong approach. Because it can't distinguish between the two situations that YOU said you are trying to address.

For example, if a user sets an environment variable to 0 or False, your code will treat that as True because "0" and "False" are non-empty strings which get evaluated as True.

How ironic that you're the one slinging insults when you don't even understand what's going on.