diff options
author | Damien George <damien@micropython.org> | 2020-06-16 21:42:50 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-06-16 22:06:30 +1000 |
commit | e0fe8ea644b54406ca82cefdc73c98cc2e9cbe9f (patch) | |
tree | 2adae065edca516ca901c7fb24d5cd48978becc4 /tests/basics/assign_expr.py | |
parent | 2c5993c59e083d11ba8b85e82eeea9c5020ac553 (diff) |
tests/basics: Add tests for assignment operator :=.
Diffstat (limited to 'tests/basics/assign_expr.py')
-rw-r--r-- | tests/basics/assign_expr.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/basics/assign_expr.py b/tests/basics/assign_expr.py new file mode 100644 index 000000000..f243905dc --- /dev/null +++ b/tests/basics/assign_expr.py @@ -0,0 +1,29 @@ +(x := 4) +print(x) + +if x := 2: + print(True) +print(x) + +print(4, x := 5) +print(x) + +x = 1 +print(x, x := 5, x) +print(x) + + +def foo(): + print("any", any((hit := i) % 5 == 3 and (hit % 2) == 0 for i in range(10))) + return hit + + +hit = 123 +print(foo()) +print(hit) # shouldn't be changed by foo + +print("any", any((hit := i) % 5 == 3 and (hit % 2) == 0 for i in range(10))) +print(hit) # should be changed by above + +print([((m := k + 1), k * m) for k in range(4)]) +print(m) |