Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Variable number of arguments to functions in Python

📅 2012-May-01 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ argument, python ⬩ 📚 Archive

Python supports variable number of arguments to functions using a simple construct: packing and unpacking of items. The star operator (discussed earlier) makes an appearance here again.

def foo( a, b=None, *c ):
    print( c )
foo( 1, 2, 3, 4, 5, 6 ) # (3, 4, 5, 6)

Tried with: Python 3.2