python format print example

In [1]:
print 'before: {:.2f} after'.format(1.5555)
before: 1.56 after
In [2]:
print '{1},{0},{1},{2},{0}'.format('pos',777,True) 
777,pos,777,True,pos
In [3]:
print '{name},{age}'.format(age=18,name='cutie')  
cutie,18
In [4]:
has=['first', 2.00, 'third']
print '1st {0[0]} all: {0} last {0[2]} end'.format(has)
1st first all: ['first', 2.0, 'third'] last third end
In [5]:
print 'start--- {:,} ---end'.format(9876543210)
start--- 9,876,543,210 ---end
In [6]:
print 'start:{:>8}'.format(123)
start:     123
In [7]:
print 'start:{:0>8}'.format(123)
start:00000123
In [8]:
print 'start:{:A>8}'.format(123)
start:AAAAA123
In [ ]:
 
In [ ]:
 
In [ ]: