Deep vs. shallow copy?

Chris Angelico rosuav at gmail.com
Thu Mar 13 19:55:44 EDT 2014


On Fri, Mar 14, 2014 at 10:41 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Are you trolling again?
>
> I'm sure that you know quite well that Python doesn't have a procedure
> type. It uses a single keyword, def, for creating both functions and
> functions-that-return-None.

I'm going to troll for a moment and give you a function that has no
return value.

def procedure():
    raise Exception

But seriously, this is something that some functions do when they need
to distinguish between returning something and not returning anything.
Look at a dictionary's subscripting (which is effectively a function
call):

>>> x={1:2}
>>> x[1]
2
>>> x[3]
Traceback (most recent call last):
  File "<pyshell#17>", line 1, in <module>
    x[3]
KeyError: 3

It can't return None to indicate "there was no such key in the
dictionary", so it raises instead. There's only one way for a Python
function to not have a return value: it has to not return.

ChrisA



More information about the Python-list mailing list