Python

String short version & Template

F.xavier 2014. 5. 10. 23:43

website = 'www.python.com'

print (website)

print (website[4:])

print (website[-3])

print (website[-3:])

 

website = 'www.%s.%s'

value = ('yahoo','com')

print (website % value)

format = 'pi with 3 decimal points %.3f'

from math import pi

print (format % pi)

 

from string import Template

s = Template('$x, glorois $x')

print(s.safe_substitute(x='Kiss'))

 

a = Template('A $thing must be never $action.')

d={}

d['thing']= 'gentleman'

d['action']= 'shows his shock'

print(a.safe_substitute(d))