Say I have a function with one mandatory and two optional arguments,
f[x_, y_ : 1, z_ : 2] := x^2 + y*z
Then how can I make a function call which gives values to both x and z, but not to y, such that y takes its default value. In Python I could call f[2, z=1] for example. What is the equivalent in Mathematica?
Yes, but that would not be practical for the cases I have in mind. It happens sometimes that I define functions with longer lists of optional arguments, and I find it cumbersome to always have to have to add all arguments up until the last one which I give a non-default value at every single function call. With the method you propose I would have a separate wrapper function for each optional argument, which with many arguments quickly gets cumbersome.
So it does not appear to work as intended. Is it a feature introduced recently to Mathematica? I did not download the newest version I think (am on version 12.1.1.0).
Well, if you’re the one defining the function, why not order the arguments in a more convenient way? Or, you could just define your function to take a list of rules (or maybe a full-blown association).