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?
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 8/31/2013 7:15 PM, Joshua Landau wrote:
On 31 August 2013 23:08, Chris Angelico wrote:
On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin
wrote:
On 31 August 2013 16:30, Chris Angelico wrote:
but doesn't solve all the cases (imagine a string or an iterator).
Similar but maybe simpler, and
On 31 August 2013 23:08, Chris Angelico wrote:
> On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin
> wrote:
>> On 31 August 2013 16:30, Chris Angelico wrote:
but doesn't solve all the cases (imagine a string or an iterator).
>>>
>>> Similar but maybe simpler, and copes with more arbitrary
On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin
wrote:
> On 31 August 2013 16:30, Chris Angelico 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), en
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
#
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.
--
http://mail.python.org/mailman/listinfo/python-l
On 31 August 2013 16:30, Chris Angelico 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 want to w
On Sat, Aug 31, 2013 at 11:33 PM, candide 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 range(n-1):
> pr
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 cod
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
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 autom
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
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
On 31 August 2013 12:16, 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,
>> # -
>>
>> ?
>>
>>
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
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 lis
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 spac
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
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
learner
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
--
ht
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 list, hence the following Python 3 code
22 matches
Mail list logo