On Wed, Sep 11, 2013, at 07:36 AM, Wayne Werner wrote:
On Sat, 31 Aug 2013, candide wrote:
# -
for i in range(5):
print(i, end=' ') # - The last ' ' is unwanted
print()
# -
Then why not define end='' instead?
I think the
On Sat, 31 Aug 2013, candide wrote:
# -
for i in range(5):
print(i, end=' ') # - The last ' ' is unwanted
print()
# -
Then why not define end='' instead?
-W
--
https://mail.python.org/mailman/listinfo/python-list
On 31.08.2013 10:17, candide wrote:
What is the equivalent in Python 3 to the following Python 2 code:
# -
for i in range(5):
print i,
# -
?
How about
print( .join(str(i) for i in range(5)))
0 1 2 3 4
Bye, Andreas
--
Le 31/08/2013 10:43, Andreas Perstinger a écrit :
How about
print( .join(str(i) for i in range(5)))
0 1 2 3 4
Thanks for your answer. The output is stricly the same but the code
doesn't suit my needs :
1) I'm porting to Python 3 a Python 2 full beginner course : the
learners are not
candide wrote:
Le 31/08/2013 10:43, Andreas Perstinger a écrit :
How about
print( .join(str(i) for i in range(5)))
0 1 2 3 4
Thanks for your answer. The output is stricly the same but the code
doesn't suit my needs :
1) I'm porting to Python 3 a Python 2 full beginner
On Sat, 31 Aug 2013 10:17:23 +0200, candide wrote:
What is the equivalent in Python 3 to the following Python 2 code:
# -
for i in range(5):
print i,
# -
?
Be careful that the above code doesn't add a trailing space after
On 8/31/13 4:17 AM, candide wrote:
What is the equivalent in Python 3 to the following Python 2 code:
# -
for i in range(5):
print i,
# -
?
Be careful that the above code doesn't add a trailing space after the
last number in the
Steven D'Aprano wrote:
On Sat, 31 Aug 2013 10:17:23 +0200, candide wrote:
What is the equivalent in Python 3 to the following Python 2 code:
# -
for i in range(5):
print i,
# -
?
Be careful that the above code doesn't
On 31 August 2013 12:16, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
On Sat, 31 Aug 2013 10:17:23 +0200, candide wrote:
What is the equivalent in Python 3 to the following Python 2 code:
# -
for i in range(5):
print i,
#
Le 31/08/2013 13:16, Steven D'Aprano a écrit :
Of course it does. Have you actually tried it?
Of course I did, redirecting the output to a file in order to spot an
eventually trailing space. I did the same for the Python 3 code.
--
http://mail.python.org/mailman/listinfo/python-list
Le 31/08/2013 12:31, Peter Otten a écrit :
softspace = False
for i in range(5):
if softspace:
print(end= )
print(i, end=)
softspace = True
print()
The if instruction imposes useless testing (we know in advance the
problem to occur at the very end of the loop) and
Le 31/08/2013 13:24, Ned Batchelder a écrit :
For a beginner course, the trailing space is fine, use this code.
I was really expecting there was a trick but I'll follow your advice,
after all the trailing space is invisible!
Nevertheless, this can be quite annoying. For instance, some
candide wrote:
Le 31/08/2013 12:31, Peter Otten a écrit :
softspace = False
for i in range(5):
if softspace:
print(end= )
print(i, end=)
softspace = True
print()
The if instruction imposes useless testing (we know in advance the
problem to occur
On Sat, 31 Aug 2013 14:59:17 +0200, candide wrote:
Le 31/08/2013 13:16, Steven D'Aprano a écrit :
Of course it does. Have you actually tried it?
Of course I did, redirecting the output to a file in order to spot an
eventually trailing space. I did the same for the Python 3 code.
On Sat, Aug 31, 2013 at 11:33 PM, candide candide@free.invalid wrote:
The if instruction imposes useless testing (we know in advance the problem
to occur at the very end of the loop) and useless writing (writing '').
The following is clearer
# -
n=5
for i in
On 31 August 2013 16:30, Chris Angelico ros...@gmail.com wrote:
but doesn't solve all the cases (imagine a string or an iterator).
Similar but maybe simpler, and copes with more arbitrary iterables:
it=iter(range(5))
print(next(it), end='')
for i in it:
print('',i, end='')
If you
Le 31/08/2013 12:31, Peter Otten a écrit :
with `softspace` saved as a file attribute, is gone in Python3.
After reading
http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function
I understand what you meant by softspace. Thanks.
--
Le 31/08/2013 15:59, Peter Otten a écrit :
To make it crystal clear, the above was to illustrate the algorithm used in
Python 2, not a suggestion.
Ok sorry, I misinterpreted.
I still think you should live with a trailing space
Are you sure ? The following code
On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin
oscar.j.benja...@gmail.com wrote:
On 31 August 2013 16:30, Chris Angelico ros...@gmail.com wrote:
but doesn't solve all the cases (imagine a string or an iterator).
Similar but maybe simpler, and copes with more arbitrary iterables:
On 31 August 2013 23:08, Chris Angelico ros...@gmail.com wrote:
On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin
oscar.j.benja...@gmail.com wrote:
On 31 August 2013 16:30, Chris Angelico ros...@gmail.com wrote:
but doesn't solve all the cases (imagine a string or an iterator).
Similar but
On 8/31/2013 7:15 PM, Joshua Landau wrote:
On 31 August 2013 23:08, Chris Angelico ros...@gmail.com wrote:
On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin
oscar.j.benja...@gmail.com wrote:
On 31 August 2013 16:30, Chris Angelico ros...@gmail.com wrote:
but doesn't solve all the cases (imagine
21 matches
Mail list logo