Ask Your Question

Declare variable as function output [closed]

asked 2015-12-28 08:32:16 -0500

bruno171092 gravatar image

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 :


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...

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by bruno171092
close date 2015-12-30 17:21:15.857904


Could you please provide the code of your function so that we can understand the problem ?

tmonteil gravatar imagetmonteil ( 2015-12-30 16:41:10 -0500 )edit

It is ok :) I just forgot to use return ;)

bruno171092 gravatar imagebruno171092 ( 2015-12-30 17:19:24 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-12-28 19:51:15 -0500

updated 2015-12-28 19:51:49 -0500

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()
sage: a = f()
sage: a
edit flag offensive delete link more


Thanks :) That was exactly the problem. I only used print instead of return :)

bruno171092 gravatar imagebruno171092 ( 2015-12-30 17:18:36 -0500 )edit

Question Tools

1 follower


Asked: 2015-12-28 08:32:16 -0500

Seen: 116 times

Last updated: Dec 28 '15