ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 30 Dec 2015 17:19:24 -0600Declare variable as function outputhttp://ask.sagemath.org/question/31886/declare-variable-as-function-output/ hello guys,
i wrote a new function, lets call it "func", that has some matrix as input and also some matrix as output.
the thing is, i want to declare the last output of the function as a new variable x ( x=func(A) for a given A) the problem is: if i say
x = func(A)
print x
i get :
none
I guess the problem is, that i calculate more than one thing while the function is running, but at the end i just want to able to use that one single output of the function for further use...Mon, 28 Dec 2015 08:32:16 -0600http://ask.sagemath.org/question/31886/declare-variable-as-function-output/Comment by bruno171092 for <p>hello guys,
i wrote a new function, lets call it "func", that has some matrix as input and also some matrix as output.
the thing is, i want to declare the last output of the function as a new variable x ( x=func(A) for a given A) the problem is: if i say </p>
<pre><code>x = func(A)
print x
</code></pre>
<p>i get :</p>
<pre><code>none
</code></pre>
<p>I guess the problem is, that i calculate more than one thing while the function is running, but at the end i just want to able to use that one single output of the function for further use...</p>
http://ask.sagemath.org/question/31886/declare-variable-as-function-output/?comment=31925#post-id-31925It is ok :)
I just forgot to use return ;)Wed, 30 Dec 2015 17:19:24 -0600http://ask.sagemath.org/question/31886/declare-variable-as-function-output/?comment=31925#post-id-31925Comment by tmonteil for <p>hello guys,
i wrote a new function, lets call it "func", that has some matrix as input and also some matrix as output.
the thing is, i want to declare the last output of the function as a new variable x ( x=func(A) for a given A) the problem is: if i say </p>
<pre><code>x = func(A)
print x
</code></pre>
<p>i get :</p>
<pre><code>none
</code></pre>
<p>I guess the problem is, that i calculate more than one thing while the function is running, but at the end i just want to able to use that one single output of the function for further use...</p>
http://ask.sagemath.org/question/31886/declare-variable-as-function-output/?comment=31923#post-id-31923Could you please provide the code of your function so that we can understand the problem ?Wed, 30 Dec 2015 16:41:10 -0600http://ask.sagemath.org/question/31886/declare-variable-as-function-output/?comment=31923#post-id-31923Answer by vdelecroix for <p>hello guys,
i wrote a new function, lets call it "func", that has some matrix as input and also some matrix as output.
the thing is, i want to declare the last output of the function as a new variable x ( x=func(A) for a given A) the problem is: if i say </p>
<pre><code>x = func(A)
print x
</code></pre>
<p>i get :</p>
<pre><code>none
</code></pre>
<p>I guess the problem is, that i calculate more than one thing while the function is running, but at the end i just want to able to use that one single output of the function for further use...</p>
http://ask.sagemath.org/question/31886/declare-variable-as-function-output/?answer=31903#post-id-31903 To actually return a value you need to use the keyword **return** as in
def f():
return 3
With the above example you can do
sage: f()
3
sage: a = f()
sage: a
3Mon, 28 Dec 2015 19:51:15 -0600http://ask.sagemath.org/question/31886/declare-variable-as-function-output/?answer=31903#post-id-31903Comment by bruno171092 for <p>To actually return a value you need to use the keyword <strong>return</strong> as in</p>
<pre><code>def f():
return 3
</code></pre>
<p>With the above example you can do</p>
<pre><code>sage: f()
3
sage: a = f()
sage: a
3
</code></pre>
http://ask.sagemath.org/question/31886/declare-variable-as-function-output/?comment=31924#post-id-31924Thanks :)
That was exactly the problem. I only used print instead of return :)Wed, 30 Dec 2015 17:18:36 -0600http://ask.sagemath.org/question/31886/declare-variable-as-function-output/?comment=31924#post-id-31924