Skip to content

Instantly share code, notes, and snippets.

@e-io
Created October 8, 2021 11:35
Show Gist options
  • Save e-io/03b0ce3d98cb74e5d3139d65994b7bdc to your computer and use it in GitHub Desktop.
Save e-io/03b0ce3d98cb74e5d3139d65994b7bdc to your computer and use it in GitHub Desktop.
string formatting
from random import randint
for m in ['', 'd', 'b', 'o', 'x', 'X', 'e', 'E', '%']:
template = 'Hello {0}, your balance is {1:=+16' + m + '}:16{2}'
print(template.format('Adam', randint(-1000, 1000), m))
print(f'{randint(-1000, 1000):+}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment