2014-03-30 16:21:24 -04:00
|
|
|
# function calls with *pos
|
|
|
|
|
2014-03-30 10:35:53 -04:00
|
|
|
def foo(a, b, c):
|
|
|
|
print(a, b, c)
|
|
|
|
|
2020-03-25 00:54:45 -04:00
|
|
|
foo(*(), 1, 2, 3)
|
|
|
|
foo(*(1,), 2, 3)
|
|
|
|
foo(*(1, 2), 3)
|
2014-03-30 10:35:53 -04:00
|
|
|
foo(*(1, 2, 3))
|
|
|
|
foo(1, *(2, 3))
|
|
|
|
foo(1, 2, *(3,))
|
|
|
|
foo(1, 2, 3, *())
|
2020-03-25 00:54:45 -04:00
|
|
|
foo(*(1,), 2, *(3,))
|
|
|
|
foo(*(1, 2), *(3,))
|
|
|
|
foo(*(1,), *(2, 3))
|
2014-03-30 10:35:53 -04:00
|
|
|
|
|
|
|
# Another sequence type
|
|
|
|
foo(1, 2, *[100])
|
|
|
|
|
|
|
|
# Iterator
|
|
|
|
foo(*range(3))
|
2014-03-30 16:21:24 -04:00
|
|
|
|
2015-12-03 12:59:49 -05:00
|
|
|
# pos then iterator
|
|
|
|
foo(1, *range(2, 4))
|
|
|
|
|
2017-01-17 00:03:30 -05:00
|
|
|
# an iterator with many elements
|
|
|
|
def foo(*rest):
|
|
|
|
print(rest)
|
|
|
|
foo(*range(10))
|
|
|
|
|
2014-03-30 16:21:24 -04:00
|
|
|
# method calls with *pos
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def foo(self, a, b, c):
|
|
|
|
print(a, b, c)
|
|
|
|
|
|
|
|
a = A()
|
2020-03-25 00:54:45 -04:00
|
|
|
a.foo(*(), 1, 2, 3)
|
|
|
|
a.foo(*(1,), 2, 3)
|
|
|
|
a.foo(*(1, 2), 3)
|
2014-03-30 16:21:24 -04:00
|
|
|
a.foo(*(1, 2, 3))
|
|
|
|
a.foo(1, *(2, 3))
|
|
|
|
a.foo(1, 2, *(3,))
|
|
|
|
a.foo(1, 2, 3, *())
|
2020-03-25 00:54:45 -04:00
|
|
|
a.foo(*(1,), 2, *(3,))
|
|
|
|
a.foo(*(1, 2), *(3,))
|
|
|
|
a.foo(*(1,), *(2, 3))
|
2014-03-30 16:21:24 -04:00
|
|
|
|
|
|
|
# Another sequence type
|
|
|
|
a.foo(1, 2, *[100])
|
|
|
|
|
|
|
|
# Iterator
|
|
|
|
a.foo(*range(3))
|