From 3c28b1eef92c38b4423e02c96fb765bb11ca00db Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Pestana Date: Sat, 28 Sep 2024 11:20:50 -0300 Subject: [PATCH] Update python.md with python operators and walrus --- source/_posts/python.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/_posts/python.md b/source/_posts/python.md index 4f54919..53f3220 100644 --- a/source/_posts/python.md +++ b/source/_posts/python.md @@ -1483,6 +1483,23 @@ resp = dict(code=0, message="OK", data=[]) successed: bool = converter(resp["message"], mapper=is_success, default=False) ``` +## Python Operators + +### Walrus {.col-span-2} + +```python +values = [1, "text", True, "", 2] +i = 0 + +# It assigns a value to a variable and compares it in a boolean expression +while (data := values[i]): + + print(data, end=",") + i = i + 1 + +# Expected result: 1, "text", True +``` + ## Miscellaneous ### Comments