Python - Numeric Number Format

Description

Numeric Number Format

Demo

num = 1 / 3.0 
print( num )                      # Auto-echoes 
print( print(num) )               # Print explicitly 
# from w  w w.  j  a v a 2  s .c o  m
print( '%e' % num )               # String formatting expression 
print( '%4.2f' % num )            # Alternative floating-point format 
print( '{0:4.2f}'.format(num) )   # String formatting method: Python 2.6, 3.0, and later

Result

The last three of these expressions employ string formatting.