fun_callstar.py 572 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # function calls with *pos
  2. def foo(a, b, c):
  3. print(a, b, c)
  4. foo(*(1, 2, 3))
  5. foo(1, *(2, 3))
  6. foo(1, 2, *(3,))
  7. foo(1, 2, 3, *())
  8. # Another sequence type
  9. foo(1, 2, *[100])
  10. # Iterator
  11. foo(*range(3))
  12. # pos then iterator
  13. foo(1, *range(2, 4))
  14. # an iterator with many elements
  15. def foo(*rest):
  16. print(rest)
  17. foo(*range(10))
  18. # method calls with *pos
  19. class A:
  20. def foo(self, a, b, c):
  21. print(a, b, c)
  22. a = A()
  23. a.foo(*(1, 2, 3))
  24. a.foo(1, *(2, 3))
  25. a.foo(1, 2, *(3,))
  26. a.foo(1, 2, 3, *())
  27. # Another sequence type
  28. a.foo(1, 2, *[100])
  29. # Iterator
  30. a.foo(*range(3))