First time here? Check out the FAQ!

Ask Your Question
1

Declare variable as function output [closed]

asked 9 years ago

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

Preview: (hide)

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 ( 9 years ago )

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

bruno171092 gravatar imagebruno171092 ( 9 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 9 years ago

vdelecroix gravatar image

updated 9 years ago

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
Preview: (hide)
link

Comments

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

bruno171092 gravatar imagebruno171092 ( 9 years ago )

Question Tools

1 follower

Stats

Asked: 9 years ago

Seen: 858 times

Last updated: Dec 29 '15