Author Topic: Python Program to display Left Aligned Strings (formatted)  (Read 836 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Python Program to display Left Aligned Strings (formatted)
« on: January 04, 2012, 04:20:05 pm »
Here is the simple Python Program to display Left Aligned Strings (formatted).

Note the format string %-8s where - is used for Left Aligned Strings

Code: (Python)
#Python Source File

array_strings = [ "AA", "AAA", "B", "BBB", "ABC", "DDBB", "ABCD", "MNIOP" ]
print "The length of the array is: %i" %len(array_strings)

for i in range(0, len(array_strings) ):
     print "Position %i Value %-8s" %(i + 1, array_strings[i])


Output:
The length of the array is: 8
Position 1 Value  AA
Position 2 Value  AAA
Position 3 Value  B
Position 4 Value  BBB
Position 5 Value  ABC
Position 6 Value  DDBB
Position 7 Value  ABCD
Position 8 Value  MNIOP

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1