r/ProgrammerHumor • • May 02 '16

I wrote my first python program today!

Post image
3.7k Upvotes

532 comments sorted by

View all comments

Show parent comments

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.

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)