Home > database >  Passing return value to function
Passing return value to function

Time:10-11

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.

CodePudding user response:

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"))

CodePudding user response:

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
  • Related