Width and Precision : Format « String « Python Tutorial

Python Tutorial
1. Introduction
2. Data Type
3. Statement
4. Operator
5. String
6. Tuple
7. List
8. Dictionary
9. Collections
10. Function
11. Class
12. File
13. Buildin Function
14. Buildin Module
15. Database
16. Regular Expressions
17. Thread
18. Tkinker
19. wxPython
20. XML
21. Network
22. CGI Web
23. Windows
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Python Tutorial » String » Format 
5. 10. 10. Width and Precision
from math import pi 

print '%10f' % pi # Field width 10 

print '%10.2f' % pi # Field width 10, precision 

print '%.2f' % pi # Precision 

print '%.5s' % 'Guido van Rossum

use an * as the width or precision (or both), in which case the number will be read from the tuple argument

print '%.*s' % (5'Guido van Rossum')
5. 10. Format
5. 10. 1. String formatting is done with the string formatting operator, the percent (%) sign.
5. 10. 2. Formatted String
5. 10. 3. String format
5. 10. 4. A basic conversion specifier
5. 10. 5. use the string format operator ( % ), or put all of the substrings in a list, and using one join() call to put them all together
5. 10. 6. The syntax for using the format operator is as follows: format_string % (arguments_to_convert)
5. 10. 7. Format Operator Auxiliary Directives
5. 10. 8. String Formatting Conversion Types
5. 10. 9. print paired with the string format operator ( % )
5. 10. 10. Width and Precision
5. 10. 11. Signs, Alignment, and Zero-Padding
5. 10. 12. A minus sign (-) left-aligns the value:
5. 10. 13. A blank (" ") means that a blank should be put in front of positive numbers
5. 10. 14. a plus (+) means that a sign should precede both positive and negative numbers
5. 10. 15. String formatting.
5. 10. 16. String-formatting codes
5. 10. 17. %[(name)][flags][width][.precision]code
5. 10. 18. The %e, %f, and %g formats display floating-point numbers in different ways, as the following interaction demonstrates:
5. 10. 19. Dictionary-Based String Formatting
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.