Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatted output in python 2

Status
Not open for further replies.

bdowen

Programmer
Jun 10, 2003
12
US
Does python have the capabilities to format output much like C or Perl??

I am still learning Python and have not come across it yet in my reading.

Any pointers about where to read more, if it is on the python website can you point me to where to look on the site.
 
Thanks for the info, it helps a lot.

One additional question: is there a way to print off, for example, 35 spaces without mannually typing in 35 spaces in the print statement?
 
alternatively, see

Code:
>>> formatstr = '%15s   %10.2f   %s'
>>> vals = [('a', 100/6.0, 'abcdef'), ('bc', 100/3.0, 'abcd'), ('def', 100/1.0, 'ab')]
>>> for t in vals:
... 	print formatstr % t
... 
              a        16.67   abcdef
             bc        33.33   abcd
            def       100.00   ab
>>>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top