Lesson 10 of 55 · Python
Arguments and Return Values
Duration: 20 minutes
Lesson 10 of 55 · Python
Duration: 20 minutes
python\ndef repeat(message, times=2):\n return message * times\n\nprint(repeat('Hi')) # HiHi\nprint(repeat('Hi', 3)) # HiHiHi\n\n\n- Positional arguments are matched by order.\n- Keyword arguments let you specify the parameter name (repeat(message='Hi', times=3)).\n- Default values (times=2) make an argument optional.\n- Use *args to collect extra positional arguments and **kwargs for extra keyword arguments.\n