Q:

How does formatting a Python date object with str.format() work?

I've recently seen this string formatting example:
>>> from datetime import date
>>> 'Today is {0:%A}'.format(date.today())
'Today is Thursday'

I'm wondering how it works.

A:

The date class defines the __format__() magic method, which is called by str.format() to produce a “formatted” string representation of an object. To quote the documentation for date.__format__():

Same as date.strftime(). This makes it possible to specify a format
  string for a date object in formatted string literals and when using
  str.format(). For a complete list of formatting directives, see
  strftime() and strptime() Behavior.

Therefore, '{:%A}'.format(date.today()) is equivalent to date.today().strftime('%A').

