Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing string with two columns

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?

like image 997
Victor Brunell Avatar asked Feb 06 '16 02:02

Victor Brunell


People also ask

How do you print the value of a string?

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.


1 Answers

You can use format and mention fix spaces between columns

'{0:10}  {1}'.format(s1, s2)

Old Style formatting

'%-10s' '%s' % (s1,s2)
like image 115
AlokThakur Avatar answered Nov 16 '22 01:11

AlokThakur