Programming Tutorials

Formatted printing in Python

By: Zed A. Shaw in python Tutorials on 2011-03-04  

Printing and formatting the printing is done quite often in any program. This simple python script just shows different ways of printing text and characters in python.

1 formatter = "%r %r %r %r"
2
3 print formatter % (1, 2, 3, 4)
4 print formatter % ("one", "two", "three", "four")
5 print formatter % (True, False, False, True)
6 print formatter % (formatter, formatter, formatter, formatter)
7 print formatter % (
8 "I had this thing.",
9 "That you could type up right.",
10 "But it didn't sing.",
11 "So I said goodnight."
12 )

What You Should See

$ python ex8.py
1 2 3 4
'one' 'two' 'three' 'four'
True False False True
'%r %r %r %r' '%r %r %r %r' '%r %r %r %r' '%r %r %r %r'
'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I said goodnight.'
$





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in python )

Latest Articles (in python)