Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41741

Re: how does the % work?

Date 2013-03-23 09:57 -0600
From Michael Torrie <torriem@gmail.com>
Subject Re: how does the % work?
References <mailman.3612.1363971987.2939.python-list@python.org> <7qbqk8p64dp4v2qvgfogvigi91gjdt5k3r@4ax.com> <514d5bef$0$30001$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.3644.1364054284.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 03/23/2013 01:38 AM, Steven D'Aprano wrote:
> Just to add confusion, the two lines are exactly the same in Python 2, 
> where Print is not a function! 

Perhaps this is a good reason use the slightly more complicated but
easier to get right format method.

print ("{0}, {1}, {2}".format(1,2,3))

And it's worth noting that using the string formatter or the old %
operator on a string works anywhere where there're strings, not just in
the print function.

b = "The answer was %d" % answer

or

b = "The answer was {0}".format(answer)

On the topic of print, I can see the logic in print being a function
now, but I have always preferred it as a print statement; it just looked
cleaner.  That was one of the things that initially attracted me to
python.  But the reality is print isn't used for much in real programs
other than console debug messages.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how does the % work? leonardo selmi <l.selmi@icloud.com> - 2013-03-22 18:06 +0100
  Re: how does the % work? John Gordon <gordon@panix.com> - 2013-03-22 17:14 +0000
  Re: how does the % work? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-22 11:06 -0700
  Re: how does the % work? Tim Roberts <timr@probo.com> - 2013-03-22 21:29 -0700
    Re: how does the % work? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-23 00:04 -0700
    Re: how does the % work? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-23 07:38 +0000
      Re: how does the % work? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-23 00:57 -0700
      Re: how does the % work? Michael Torrie <torriem@gmail.com> - 2013-03-23 09:57 -0600
        Re: how does the % work? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-23 23:53 +0000
      Re: how does the % work? leonardo <tampucciolina@libero.it> - 2013-03-23 18:05 +0100
        Re: how does the % work? Tim Roberts <timr@probo.com> - 2013-03-24 16:35 -0700

csiph-web