Very easy trick, but in the most cases it's
This is
Returning something from a function, requires that the caller assign the result.
But the caller can't see from outside, whats happening inside the function.
It's a kind of black box for the caller. You call it with something and then you get something back.
Then the interpreter calls the object, which is referenced by
On the caller side, the return value is assigned to the name
A
Edit:
If you see something like this:
In this case the programmer expect 4 return values (objects).
If there is one name to less or too much, it won't work.
This technique is called
In addition, there is a Extended Iterable Unpacking.
I can't find the old pep.
True
.def foo(): name = 'Foo' return nameEverything, which is indented, is not accessible from outside.
This is
True
for functions, which don't use global variables.Returning something from a function, requires that the caller assign the result.
But the caller can't see from outside, whats happening inside the function.
It's a kind of black box for the caller. You call it with something and then you get something back.
# I'm the caller my_result = foo()First the interpreter searches for the name foo (it could be everything).
Then the interpreter calls the object, which is referenced by
foo
. The function foo is executed and return the result.On the caller side, the return value is assigned to the name
result
.A
=
sign means always assignment to a name. (I don't like to use the term variable for it).Edit:
If you see something like this:
a, b, c, d = some_function()Then there is a step before assignment.
In this case the programmer expect 4 return values (objects).
If there is one name to less or too much, it won't work.
This technique is called
Iterable Unpacking
.In addition, there is a Extended Iterable Unpacking.
I can't find the old pep.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!