Created
November 12, 2017 06:02
-
-
Save jaycody/dadcee9b590c150df1add5c24d76596e to your computer and use it in GitHub Desktop.
Parameters for spacing the format function results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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