Skip to content

Instantly share code, notes, and snippets.

@jaycody
Created November 12, 2017 06:02
Show Gist options
  • Save jaycody/dadcee9b590c150df1add5c24d76596e to your computer and use it in GitHub Desktop.
Save jaycody/dadcee9b590c150df1add5c24d76596e to your computer and use it in GitHub Desktop.
Parameters for spacing the format function results
""" FORMAT THE format() and UNPACK THE *args """
res = ['Homie McHomeboy', 35, 24.798] # print this
args = (10, 5, 2.2) # with these dimensions
print('{0[0]:{1}s} {0[1]:{2}d} {0[2]:{3}f}'.format(res, *args))
## where:
## 's' # format a STRING with n spaces, left justified by defau
## 'd' # format an INT reserving n spaces, right justified by default
## 'f' # format a float, reserving n spaces, and .n spaces after the decimal point, right justfied by default.
## AND UNPACK THE *args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment