[This was a bit harsh. Here's a better documentation.](http://docs.python.org/2/library/string.html#format-specification-mini-language)

Basically your code can be simplified to something like (i didn't test but you get the idea):
```python
def bar(msg, width=40):
  fmt = '{0:=^%d}' % width
  return fmt.format(' %s ' % msg)
```

I'm not sure about the `position` thing.