Formatted printing in Python

By: Zed A. Shaw Emailed: 1675 times Printed: 2154 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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.'
$


python Home | All python Tutorials | Latest python Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Zed A. Shaw
Formatted printing in Python
Printing in Python
Strings And Text in Python
Variables And Printing in Python
Variables And Names in Python
Numbers And Math in Python
Comments And Pound Characters in Python
Your First Program in Python
Installing gedit for python programming in Linux
Installing gedit for python programming in Mac OS X

More Tutorials in python
What is the need for Python language?
How to compile python script and create .pyc file?
How to find the current module name in python
How to force rereading of a changed module in python
UnboundLocalError in python
call by reference in python
Callable objects in python
Ternary operator in python
Hexadecimal and Octal integers in python
Convert string to number in python
Convert number to string in python
Perl's chomp() equivalent for removing trailing newlines from strings in python
Convert between tuples and lists in python
Iterate over a sequence in reverse order in python
Remove duplicates from a list in python

More Latest News
Most Viewed Articles (in python )
How to find the current module name in python
Installing gedit for python programming in Windows
Installing gedit for python programming in Linux
Comments And Pound Characters in Python
Numbers And Math in Python
Strings And Text in Python
Formatted printing in Python
Using Unicode Literals in Python
Unknown command: 'migrate'
error: â_mysql_ConnectionObjectâ has no member named
What is the need for Python language?
How to force rereading of a changed module in python
Callable objects in python
Ternary operator in python
Array in python
Most Emailed Articles (in python)
Installing gedit for python programming in Windows
switch case statement in Python
Comments And Pound Characters in Python
Unknown command: 'migrate'
What is the need for Python language?
with in Python
Numbers And Math in Python
Variables And Names in Python
Formatted printing in Python
How to find the current module name in python
call by reference in python
Hexadecimal and Octal integers in python
Convert string to number in python
Remove duplicates from a list in python
Multidimensional list (array) in python