Formatted printing in Python
By: Zed A. Shaw Printer Friendly Format
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.'
$
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
How to install Jupyter in Ubuntu and make it accessible through Apache Reverse Proxy
Python Basics - Setting up your Python Development Environment
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