First time here? Check out the FAQ!

Ask Your Question
1

How to define Sage function with Optional arguments?

asked 8 years ago

Vova gravatar image

updated 8 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 8 years ago

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:

Preview: (hide)
link

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: 8 years ago

Seen: 1,586 times

Last updated: Oct 19 '16