0

I have read the Python docs about the print statement. With the following situation (2) not understood.

A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line. This is the case

  1. when no characters have yet been written to standard output,
  2. when the last character written to standard output is a whitespace character except ' ', or
  3. when the last write operation on standard output was not a print statement.

I have test this behavior with the following code. However, it does not print 1 and 2 on different lines since '\t' is a whitespace and is obviously not a ' '.

print 1, '\t',
print 2
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
andy
  • 3,951
  • 9
  • 29
  • 40
  • 1
    You have included a trailing comma, which *explicitly* suppresses the newline. – jonrsharpe Jan 24 '15 at 10:29
  • And you are a decade behind, upgrade to Python 3 now! – Ulrich Eckhardt Jan 24 '15 at 10:30
  • @UlrichEckhardt only six years, so far! – jonrsharpe Jan 24 '15 at 10:31
  • @jonrsharpe, so in order to print a string in a new line, i only have to write a `print` clause without a trailing comma. Does it have another way to do this. – andy Jan 24 '15 at 10:57
  • @andy 1. Try it and see! 2. Per the Zen of Python (`import this`) *"There should be one-- and preferably only one --obvious way to do it."*. Although if you `from __future__ import print_function` you can use 3.x's `print` implementation, and explicitly specify the `end` for each call. – jonrsharpe Jan 24 '15 at 11:00

0 Answers0