You now know how the new walrus operator works and how you can use it in your own code. By using the
:= syntax, you can avoid different kinds of repetition in your code and make your code both more efficient and easier to read and maintain. At the same time, you shouldn’t use assignment expressions everywhere. They will only help you in some use cases.
In this course, you learned how to:
- Identify the walrus operator and understand its meaning
- Understand use cases for the walrus operator
- Avoid repetitive code by using the walrus operator
- Convert between code using the walrus operator and code using other assignment methods
- Understand the impacts on backward compatibility when using the walrus operator
- Use appropriate style in your assignment expressions
To learn more about the details of assignment expressions, see PEP 572. You can also check out the PyCon 2019 talk PEP 572: The Walrus Operator, where Dustin Ingram gives an overview of both the walrus operator and the discussion around the new PEP.
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.