Ask Your Question
1

Declare variable as function output [closed]

asked 2015-12-28 15:32:16 +0200

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 :

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

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-31 00:21:15.857904

Comments

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

tmonteil gravatar imagetmonteil ( 2015-12-30 23:41:10 +0200 )edit

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

bruno171092 gravatar imagebruno171092 ( 2015-12-31 00:19:24 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-12-29 02:51:15 +0200

vdelecroix gravatar image

updated 2015-12-29 02:51:49 +0200

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
3
edit flag offensive delete link more

Comments

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

bruno171092 gravatar imagebruno171092 ( 2015-12-31 00:18:36 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-28 15:32:16 +0200

Seen: 458 times

Last updated: Dec 29 '15