Q:

What's the usage of a a def in a function?

Just reading the Python doc's in particular this page, in regards to attrgetter and itemgetter.
I'm struggling to understand the usage of the usage of def and return in the code examples. Not the usage of those functions.
It seems like a lamdba, but I don't know how to interpret it.
EDIT

I think it just clicked. The attrgetter is like a constructor for the resolve_attr function? This was a little confusing, as i'd normally expect the code for a def to be between the def and the return. The code on the return is like a lambda. To add to the confusion the arg ojb is the argument passed to the returned object. Arhhhhh.....

What do i need to know for this to make sense?
This is the code example I'm referring to:
   def attrgetter(*items):
    if any(not isinstance(item, str) for item in items):
        raise TypeError('attribute name must be a string')
    if len(items) == 1:
        attr = items[0]
        def g(obj): #What is this
            return resolve_attr(obj, attr)
    else:
        def g(obj):#And this?
            return tuple(resolve_attr(obj, attr) for attr in items)
    return g

def resolve_attr(obj, attr):
    for name in attr.split("."):
        obj = getattr(obj, name)
    return obj

A:

def is the keyword to define a function.
These are just functions defined inside another function  attrgetter()
That's why you have multiple return inside attrgetter()
g looks like lambda because attrgetter()  returns a function, and not the result directly. 
g could be replaced by a lambda declaration indeed.

A:

In Python, functions are just like normal object. You can pass them around, and (as in the example above) return them from other functions.
The example function, returns another function as its return value. It does so by defining a function (that's the def g(ojb): line) and then simply returning it.
You can do this, because in Python - a function is just like any other object.

