0

Say I have a function

def equals_to(x,y):
 a + b = c
def some_function(something):
 for i in something:
 ...

Is there a way to use c that was calculated by equals_to as a parameter for some_function like this

equals_to(1,2)
some_function(c)
3
  • what are c, a and b? Where are they from? Commented Dec 7, 2012 at 9:06
  • I'm very confused by what you're trying to accomplish. equals_to doesn't compile, it looks like it's meant to return an integer, which wouldn't work in a for x in blah statement. Commented Dec 7, 2012 at 9:08
  • ` def equals_to(x,y)` should have said def equals_to(a,b) I made a mistake while typing out the example. Also a + b = c should have been c = a + b Commented Dec 7, 2012 at 12:23

1 Answer 1

3

You need to return the value of c from the function.

def equals_to(x,y):
    c = x + y           # c = x + y not a + b = c
    return c            # return the value of c 

def some_function(something):
    for i in something:
    ... 
    return 

sum = equals_to(1,2)     # set sum to the return value from the function 
some_function(sum)       # pass sum to some_function

Also the function signature of equals_to takes the arguments x,y but in the function you use a,b and your assignment was the wrong way round, c takes the value of x + y not a + b equals c.

Strongly recommend: http://docs.python.org/2/tutorial/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.