How To Simplify Boolean Expressions // Python Tips

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


🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

In my opinion this applies only when you use type hints, so yeah most of the time. Even tho I like the pytonic way, sometimes I still find easier to read the more explicit way. Anyway good video

byte__
Автор

I like the videos overall, but disagree with this. As someone who's now getting neck-deep into Python, I like my code to be as explicit (and logical step-wise) as possible. So, if you have to <i>implicitly</i> understand something, that makes it less readable, not more so.

Whatthetrash
Автор

This also makes the code more flexible. For example, should code need to support tickets set to None. The length check will not work with None but the "if tickets" works with lists, None, and other types.

POINTS
Автор

For the example given I would go further. I use typehints and do not allow warnings, so I know the parameter is a list therefore I would not care if it was empty so remove the if statement altogether. The comment even says if it is empty don't do anything yet it prints to stdout.

dmail
Автор

I've seen a lot of people using a similar technique to check whether a particular variable is `None`, but that can be dangerous (for instance, numpy will throw an exception if you try this on an array). I'm inclined to be more explicit than what's demonstrated in the video.

hankwikle
Автор

One place where it can be dangerous is doing that on an integer to check whether it is None. The expression will value to False whether it's None, or 0.

VaderFuntime
Автор

Don't use that if tickets is not strictly typed. It can quickly go wrong if tickets is Optional (could be None).
Overall, as python dzen says, explicit is always better than implicit, you really gotta know all possible side effects of implicit conversions.

forsee
Автор

alternatively use for-else:
for ticket in tickets:
ticket.process()
else:
print("There are no tickets to process")

reyjanson
Автор

Might be interesting to take it a step further here and implement the little known Python "for/else" statement.

sheanmassey
Автор

In my opinion Shorts are not a good solution for your channel. I've to watch from the beginning to the end, cant jump to the point I want.

teprox
Автор

Your statment won't work if you have one or more tickets.

PaCmEn
visit shbcf.ru