0

How do I use optional arguments in python?

I'm making a function for a homework that use 3 arguments but only 2 are strictly needed, is there a way to make the function work if the user forget to give the third argument?... sorry for my english by the way

11th Oct 2017, 10:05 PM
Daniel Andrés Gonzålez Llano
Daniel Andrés Gonzålez Llano - avatar
1 Answer
+ 1
def myfunction(needthis, needthis2, optional=1): Basically set the optional argument to a default value and if you only pass two arguments optional is set to the default (in this case 1)
12th Oct 2017, 12:17 AM
Cory