Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22416
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: string interpolation for python |
| Date | 2012-03-31 06:29 -0400 |
| References | <CABgq=FyhR+Ldujj3YKRBpVXRVoeoayuXZviUUcNx-gXnFiHLSw@mail.gmail.com> <CACoeR0xV=28j6rFHm1ep3gzH9C0sbDqyxRRwX-JrVm3G+rrXww@mail.gmail.com> <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1177.1333189777.3037.python-list@python.org> (permalink) |
On 3/31/2012 2:22 AM, Yingjie Lan wrote:
> Hi all,
>
> I'd really like to share this idea of string interpolation for formatting.
> Let's start with some code:
>
> >>> name = "Shrek"
> >>> print( "Hi, $name$!")
> Hi, Shrek!
> >>> balls = 30
> >>> print( "We have $balls$ balls.")
> We have 30 balls
You can already do essentially that without adding a special-case string
formatting method to the general methods we already have.
>>> balls = 5
>>> people = 3
>>> 'The {people} people have {balls} balls.'.format(**locals())
'The 3 people have 5 balls.'
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: string interpolation for python Terry Reedy <tjreedy@udel.edu> - 2012-03-31 06:29 -0400 Re: string interpolation for python Steve Howell <showell30@yahoo.com> - 2012-03-31 10:51 -0700
csiph-web