Ask Your Question
1

How to define Sage function with Optional arguments?

asked 2016-10-19 20:56:35 +0100

Vova gravatar image

updated 2016-10-19 21:04:06 +0100

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 21:34:08 +0100

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 20:56:35 +0100

Seen: 1,501 times

Last updated: Oct 19 '16