Question about return


Ok, so if we use list.pop to pull the value out of the list and it gets “returned” to us, how can we use that information that got returned?

Can it be printed? If so, how?
Can it be used for new functions or as a variable in new lists?

I’m curious because this “return” thing is confusing to me as well. I think I understand how it works if I define a function and have it return a value after the function completes its code, but I don’t understand in this list.pop scenario since it seems like the returned value is just floating in limbo with no way to call it back.

(I’m obviously confused and sorry if I mis-use any terminology, I am just starting out.)

Removing elements from lists (return)

look at this example:

def hello():
    return "hello world"

x = hello()

i store the returned result in variable named x. The same thing happens with .pop(), this method also uses return to hand you back the removed value. What you do with this returned value, is up to you.


This might help

def Greetings():
return “Greetings India!”

x = Greetings()



This is very similar to my code? Except you didn’t use format so indent doesn’t show up, and your naming doesn’t follow style guide, and there is no explanation.


return is used to get the output of a function as a value which can be used in other functions or assignments etc;

def hello():
    return "hello world"

x = hello()

After running the code above, x's value becomes the output of hello() - what it returned. Therefore x = "hello world".

You could also use it like this:

def timesTwo(x):
    return x*2

def plusOne(y):
    return y+1

a = plusOne(timesTwo(5))

Above are two functions - the first multiplies the input by 2, the second adds 1 to the input - they both return the output to be used by anything calling the function.

On the last line, we call both functions, one inside the other. This results in a being set to (5*2)+1 which equals 11

…does any of that make sense?


I am very sorry, I did not mean to cause any trouble also your post didn’t show up for me.