Using Assert Will Save Your Code - Python

preview_player
Показать описание
Learn how to use Python's assert to add an additional layer of protection to your code.

Рекомендации по теме
Комментарии
Автор

Could you increase the font size please?

alvaromoe
Автор

I started learning python and instantly got this video recommended! I guess the youtube algorithm is working hehe :)

udfin
Автор

This is rad! Really like how to-the-point this is.

For production code I would build a Sandwich class with the ingredient attributes with Literal types or enums, and evaluate those on startup - throwing KeyError and ValueError exceptions for missing required attributes or values from outside of the enum. The bonus here is you can also store the Sandwich class (or its internal ingredient variables) as a class variable in SandwichMaker to force the IDE to return possible autocomplete values.

rob
Автор

This is more of a critique of the thumbnail but "if" will exit when the condition is true, while "assert" will exit if the condition is false

bettercalldelta
Автор

Curious -- isn't this the point of unit tests and other testing? Eg. Wouldn't you typically write some tests to assert these things rather than putting it in your actual code and having to take it out later? What would be the advantage of `assert` over testing?

okamimoushiyou
Автор

Forgive me if this sounds noob, but can't you just do a if-else?

victorajayi
Автор

I would normally leave a like but I'm not in this video

murphygreen
Автор

I'm still figuring out how the saving part happened... so, what do you mean by "save" like you could've lost it or ... ?

haralc
Автор

Very helpful video! Asserts now feel useful to me. Thank you.

noaheben
Автор

You should zoom in a bit into your code, viewing on mobile is kinda hard. Nice video tho.

_jaime.