Python 3.8 introduced the walrus operator, := a colon followed by an equal sign. It allows us to combined the evaluation of an expression with the name assignment into one statement. For example, an expression that appears in an if condition is resolved and then evaluated in a boolean context.
With the walrus operator, the expression is resolved, the result is assigned to the left-hand name and is then evaluated in the surrounding context. In the example I use, the walrus operator saves us one line. However, this could also be achieved by simply assigning n before the if condition and then evaluating n.
I actually had problems coming up with creative new examples that show the usefulness of the walrus operator and I am not convinced yet that it is worth the new feature. But there are definitely known examples where the walrus operator saves a line of code and also saves computation time by only evaluating once. For more details check out the PEP 572 that details the rational for adding the walrus operator to python.
PEP 572:
https://www.python.org/dev/peps/pep-0...
Смотрите видео The Walrus Operator - New in Python 3.8 онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь DMK Data 16 Ноябрь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 82 раз и оно понравилось 2 людям.