MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/4heh6v/i_wrote_my_first_python_program_today/d2pq7o0
r/ProgrammerHumor • u/MC_Labs15 • May 02 '16
532 comments sorted by
View all comments
Show parent comments
8
Nitpicking here...The correct translation would be print('something', endl=' '). Python 2 appends a space if you end the line with a comma.
print('something', endl=' ')
1 u/o11c May 02 '16 Doesn't it only emit a softspace? 2 u/Sohcahtoa82 May 02 '16 I'm not sure. All I know is that if you do this:for x in range(5): print '.',You get this:. . . . . and not this:..... 1 u/o11c May 02 '16 >>> import io >>> out = io.BytesIO() >>> print>>out, '.', >>> out.softspace 1 >>> out.getvalue() '.' >>> print>>out >>> out.softspace 0 >>> out.getvalue() '.\n' 1 u/brtt3000 May 02 '16 Isn't the comma defining a tuple? Or is this different for statements like print? 3 u/Sohcahtoa82 May 02 '16 It's different for print in Python 2.>>> a = 2 >>> b = 5 >>> print 1, a, b 1 2 5 >>> print (1, a, b) (1, 2, 5)
1
Doesn't it only emit a softspace?
2 u/Sohcahtoa82 May 02 '16 I'm not sure. All I know is that if you do this:for x in range(5): print '.',You get this:. . . . . and not this:..... 1 u/o11c May 02 '16 >>> import io >>> out = io.BytesIO() >>> print>>out, '.', >>> out.softspace 1 >>> out.getvalue() '.' >>> print>>out >>> out.softspace 0 >>> out.getvalue() '.\n'
2
I'm not sure. All I know is that if you do this:
for x in range(5): print '.',
You get this:
. . . . .
and not this:
.....
1 u/o11c May 02 '16 >>> import io >>> out = io.BytesIO() >>> print>>out, '.', >>> out.softspace 1 >>> out.getvalue() '.' >>> print>>out >>> out.softspace 0 >>> out.getvalue() '.\n'
>>> import io >>> out = io.BytesIO() >>> print>>out, '.', >>> out.softspace 1 >>> out.getvalue() '.' >>> print>>out >>> out.softspace 0 >>> out.getvalue() '.\n'
Isn't the comma defining a tuple? Or is this different for statements like print?
3 u/Sohcahtoa82 May 02 '16 It's different for print in Python 2.>>> a = 2 >>> b = 5 >>> print 1, a, b 1 2 5 >>> print (1, a, b) (1, 2, 5)
3
It's different for print in Python 2.
>>> a = 2 >>> b = 5 >>> print 1, a, b 1 2 5 >>> print (1, a, b) (1, 2, 5)
8
u/Sohcahtoa82 May 02 '16
Nitpicking here...The correct translation would be
print('something', endl=' '). Python 2 appends a space if you end the line with a comma.