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
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
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}
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
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
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,
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, "&"
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
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, "."))
>
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
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
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?
12 matches
Mail list logo