On 12/19/2014 03:25 AM, Lei wrote:
Hi experts,
I am using python 3.
I wrote in IPython console in Spyder
for elem in [10, 20, 25, 27, 28.5]:
print(elem),
But the results are
10
20
25
27
28.5
As I learned, the comma in the syntax "print(elem)," will prevent the
use of newline character. Why does it not work here?
That works in Python 2:
In [1]: for elem in [10, 20, 25, 27, 28.5]:
...: print(elem),
...:
10 20 25 27 28.5
but not using the print function from Python3:
In [3]: from __future__ import print_function
In [4]: for elem in [10, 20, 25, 27, 28.5]:
print(elem),
...:
10
20
25
27
28.5
To get it to work do:
In [5]: for elem in [10, 20, 25, 27, 28.5]:
print(elem, end=',')
...:
10,20,25,27,28.5,
How can I make the results in one line? Like
10 20 25 27 28.5
I know I can use
print([elem for elem in [10, 20, 25, 27, 28.5]])
and I get
[10, 20, 25, 27, 28.5]
But this is not something I want. What I want is, with the first codes,
why the results are in vertical line, even with the comma?
Thanks!
--
You received this message because you are subscribed to the Google
Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.
--
Adrian Klaver
[email protected]
--
You received this message because you are subscribed to the Google Groups
"spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.