Ask Your Question
1

How to define Sage function with Optional arguments?

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

Vova gravatar image

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

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
2

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

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]
    <etc>

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

Stats

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

Seen: 138 times

Last updated: Oct 19 '16