Author Topic: Python Program to display Right Aligned Strings (formatted)  (Read 948 times)

kathir

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

Note the format string %8s meaning Right aligned strings by default

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
« Last Edit: January 04, 2012, 04:20:45 pm by kathir »

 


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