Passing return value to function

Question:

I’m having difficulty understanding how to use return values.

def grab_name(string):
    return grab("users/self/profile", string)

    def print_user_info(arg):
        print(grab("users/self/profile", "janice"))

I need to consume the result of passing the first function in order to print the user info. But I’m not sure how to do that…the second function is not supposed to consume a string or call the function directly. I understand the return value doesn’t exist outside the scope of the first function so I don’t understand how to get the value into the second function without just calling it directly as I have above.

The first function is basically returning a dictionary and the second function needs to consume the result of calling the first function.

Asked By: speeed3

||

Answers:

I think this small modification is what you are seeking.

def grab_name(string):
    return grab("users/self/profile", string)

def print_user_info(arg):
    print(grab_name("janice"))
Answered By: Tim Roberts
def grab_name(string):
    return grab("users/self/profile", string)

def print_user_info(arg):
    return "janice"
    
print(print_user_info(grab_name))  

result :

janice
Answered By: Essence
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.