def __repr__(self):
    return '<Foo as repr, with \xc3\xa5\xc3\xa9\xc3\xa6 some non-ASCII>'

def __format__(self, spec):
    return 'Foo formatted to {!r} spec'.format(spec)
print("""Different conversions applied:
!s: {0!s:>60s}
!r: {0!r:>60s}
!a: {0!a:>60s}
No conversions: {0:>50s}
""".format(
    Foo()))
Using !s vs. :s to format a string in Python