diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-30 21:21:24 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-30 21:21:24 +0100 |
commit | 230fec77d7bd9bae5e86a009d549550d6047fd07 (patch) | |
tree | 2620e7898155d2973153fba69cab5aab0ace54d0 /tests/basics/fun-callstar.py | |
parent | f6a820903afe12760b27553831c3bdb16c50b985 (diff) | |
download | micropython-230fec77d7bd9bae5e86a009d549550d6047fd07.tar.gz micropython-230fec77d7bd9bae5e86a009d549550d6047fd07.zip |
py: Implement positional and keyword args via * and **.
Extends previous implementation with * for function calls to * and **
for both function and method calls.
Diffstat (limited to 'tests/basics/fun-callstar.py')
-rw-r--r-- | tests/basics/fun-callstar.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/basics/fun-callstar.py b/tests/basics/fun-callstar.py index 49b40d9594..255563b26b 100644 --- a/tests/basics/fun-callstar.py +++ b/tests/basics/fun-callstar.py @@ -1,3 +1,5 @@ +# function calls with *pos + def foo(a, b, c): print(a, b, c) @@ -11,3 +13,21 @@ foo(1, 2, *[100]) # Iterator foo(*range(3)) + +# method calls with *pos + +class A: + def foo(self, a, b, c): + print(a, b, c) + +a = A() +a.foo(*(1, 2, 3)) +a.foo(1, *(2, 3)) +a.foo(1, 2, *(3,)) +a.foo(1, 2, 3, *()) + +# Another sequence type +a.foo(1, 2, *[100]) + +# Iterator +a.foo(*range(3)) |