Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Steven D'Aprano
On Sun, Jan 03, 2016 at 01:12:41PM +, Alan Gauld wrote: > Why is it better? > 1) It is slightly more performant. Consider that format has to build the entire output as a new string in advance: "You've visited {0} & {2}.".format(island, new) gets generated before being passed to print for

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Steven D'Aprano
On Sun, Jan 03, 2016 at 02:04:22PM +0100, Chris Warrick wrote: > Here are a couple of reasons: > * String formatting works everywhere, but this syntax is specific to > print() — if you use something else, you might end up producing faulty > code That argument doesn't make sense to me. I think you

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Steven D'Aprano
On Sun, Jan 03, 2016 at 02:27:01PM +0200, yehudak . wrote: > Hi there, > In a program I wrote the following line (Python 3.5): > > print("You've visited", island, '&', new + ".") > > A programmer told me that it's a bad habit, and I should have used instead: > > print("You've visited {0} {1} {2}

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Alan Gauld
On 03/01/16 13:09, Peter Otten wrote: > In future versions of Python you can simplify it to > > print(f"You've visited {island}, & {new}.") > > https://www.python.org/dev/peps/pep-0498/ I hadn't seen that before. Interesting link, thanks. I think I like it but only time and experience will

Re: [Tutor] Tutor Digest, Vol 143, Issue 4

2016-01-03 Thread yehudak .
Thank you ALL for your kind help. Yehuda On Sun, Jan 3, 2016 at 3:12 PM, wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a mess

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread yehudak .
Important point. Thanks again. Yehuda On Sun, Jan 3, 2016 at 3:10 PM, Francois Dion wrote: > And as Chris points out, if there is any possibility that the words will > be in a different order in a different language, use {0}, {1} instead of {}. > > > Francois > > On Sun, Jan 3, 2016 at 8:04 AM,

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Alan Gauld
On 03/01/16 12:27, yehudak . wrote: > Hi there, > In a program I wrote the following line (Python 3.5): > > print("You've visited", island, '&', new + ".") > > A programmer told me that it's a bad habit, and I should have used instead: > > print("You've visited {0} {1} {2}{3}".format(island, "&"

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Francois Dion
And as Chris points out, if there is any possibility that the words will be in a different order in a different language, use {0}, {1} instead of {}. Francois On Sun, Jan 3, 2016 at 8:04 AM, Chris Warrick wrote: > On 3 January 2016 at 13:27, yehudak . wrote: > > Hi there, > > In a program I w

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Peter Otten
yehudak . wrote: > Hi there, > In a program I wrote the following line (Python 3.5): > > print("You've visited", island, '&', new + ".") > > A programmer told me that it's a bad habit, and I should have used > instead: > > print("You've visited {0} {1} {2}{3}".format(island, "&", new, ".")) >

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Francois Dion
The answer is neither. The second shows the intent in part but doesn't quite get it right. The intent is to have a string template and insert values in that template: print("You've visited {} & {}.".format(island, new) This is totally clear what is going to happen. I'm not relying on the behavio

Re: [Tutor] To FORMAT or not to

2016-01-03 Thread Chris Warrick
On 3 January 2016 at 13:27, yehudak . wrote: > Hi there, > In a program I wrote the following line (Python 3.5): > > print("You've visited", island, '&', new + ".") > > A programmer told me that it's a bad habit, and I should have used instead: > > print("You've visited {0} {1} {2}{3}".format(isla

[Tutor] To FORMAT or not to

2016-01-03 Thread yehudak .
Hi there, In a program I wrote the following line (Python 3.5): print("You've visited", island, '&', new + ".") A programmer told me that it's a bad habit, and I should have used instead: print("You've visited {0} {1} {2}{3}".format(island, "&", new, ".")) May I understand why?