Skip to content

Instantly share code, notes, and snippets.

@christabor
Last active May 15, 2017 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christabor/bb668a2490ba120340d5212b1245239b to your computer and use it in GitHub Desktop.
Save christabor/bb668a2490ba120340d5212b1245239b to your computer and use it in GitHub Desktop.
Crazy str formatting
print('-' * 80)
for x in range(10):
print('{num}: {:.>{pad1}d} {:.>{pad2}d} {:.>{pad3}d} {:.>{pad4}d}'.format(x ** 2, x ** 3, x ** 4, x ** 5, num=x, pad1=10, pad2=20, pad3=30, pad4=40))
class Kaboom(object):
def __format__(self, format):
if format == 'explode':
return '*' * 80
return 'kaboom'
'{:explode}'.format(Kaboom())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment