Ask Your Question

How to define Sage function with Optional arguments?

asked 2016-10-19 13:56:35 -0600

Vova gravatar image

updated 2016-10-19 14:04:06 -0600

I need to define a Sage function with optional arguments. The number of mandatory arguments is 2 and there are up to 3 optional arguments. How do I do this is Sage?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-10-19 14:34:08 -0600

kcrisman gravatar image

To do optional arguments in Python (and hence, Sage), the idiom is something like

def f(a=2,b=3,*args):
    <function definition>
    first_optional_argument = args[0]

where args then becomes a list of the optional arguments. See much more detailed stuff:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-10-19 13:56:35 -0600

Seen: 933 times

Last updated: Oct 19 '16