Advertisement
wagner-cipriano

PEP 292 - Simpler String Substitutions

Oct 12th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. #String interpolation
  2. from __future__ import print_function      #Compatibilidade func print python 2/3
  3.  
  4. s = '%s was born in the %s.'
  5. print (  s %('Guido', 'Netherlands'))
  6.  
  7. #Now, with Python PEP 292 (Simpler String Substitutions):
  8. from string import Template
  9. s = Template('${name} was born in the ${country}.')
  10. print (s.substitute(name='Guido', country='Netherlands'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement