ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 02 Jan 2021 14:03:10 +0100interact variables work differentlyhttps://ask.sagemath.org/question/54068/interact-variables-work-differently/This interact works but I'm unclear why I only need n in the body of the function, but ymax alone fails. I have to make it ymax=ymax. They should both work the same.
@interact
def _(n=(1,20),ymax=(50,200)):
show(plot([.5*x^2,x^2,2*x^2],-n,n,legend_label=[".5*x^2","x^2","2*x^2"],aspect_ratio=.2),ymax=ymax)Thu, 29 Oct 2020 02:07:48 +0100https://ask.sagemath.org/question/54068/interact-variables-work-differently/Answer by slelievre for <p>This interact works but I'm unclear why I only need n in the body of the function, but ymax alone fails. I have to make it ymax=ymax. They should both work the same.</p>
<pre><code>@interact
def _(n=(1,20),ymax=(50,200)):
show(plot([.5*x^2,x^2,2*x^2],-n,n,legend_label=[".5*x^2","x^2","2*x^2"],aspect_ratio=.2),ymax=ymax)
</code></pre>
https://ask.sagemath.org/question/54068/interact-variables-work-differently/?answer=55070#post-id-55070This is because of the difference between positional arguments
and keyword arguments in Python functions.
More detail can be found in the Python documentation
- [Python documentation: calls](https://docs.python.org/3/reference/expressions.html#calls)
Tutorials can also be found by querying web search engines
for [ positional arguments keyword arguments Python ].Sat, 02 Jan 2021 14:03:10 +0100https://ask.sagemath.org/question/54068/interact-variables-work-differently/?answer=55070#post-id-55070