I am new to python and was wonder how to use the return statement from a def in another def how would I implement that. I know it’s probably an obvious answer but I’m stuck.
def equal(A):
if A == 2:
return ("true")
if A != 2:
return "false"
for example, if I wanted to use "true" or "false" to affect something else
>Solution :
You should use the Python truth values True and False as returns. Also you should use if/else rather than two if clauses. So your function should be:
def equal(A):
if A == 2:
return True
else:
return False # if you get here you know that A does not equal 2
Or more simply:
def equal(A)
if A == 2:
return True
return False # no need for the second clause
To use those values in another function you could do something like
def test(some_parameter)
answer = equal(some_parameter)
if answer == True:
# do one thing
else: # it is False
# do something else
I would also strongly recommend you go to The Python Tutorial and work through at least the first six chapters.