I'm trying to print a string with two fixed columns. For example, I'd like to be able to print:
abc xyz
abcde xyz
a xyz
What is the correct way to format the output string when printing to achieve this? Also, how is this done before version 2.6 and after version 2.6?
You first include the character f before the opening and closing quotation marks, inside the print() function. To print a variable with a string in one line, you again include the character f in the same place – right before the quotation marks.
You can use format and mention fix spaces between columns
'{0:10} {1}'.format(s1, s2)
Old Style formatting
'%-10s' '%s' % (s1,s2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With