On Sat, 30 Jul 2016 10:27 pm, BartC wrote:

> This is one thing I can never get right in Python: controlling when a
> newline is or isn't generated and what happens with separators.

In Python 3, that's easy: the default space separator and newline at the end
can both be customized to any string you like:

print(x, y, z, sep=' +++ ', end='\n\tEND\n')

individually or together, including the empty string:

print(x, y, z, sep='\n', end='')

And naturally, since these are just ordinary function arguments, they are
restricted to constant literals. They can be variables or expressions:

print(x, y, z, end=(get_output_end() or OUTPUT_END))



[...]
> (Some languages use 'write' or 'writeln', or 'print' or 'println'; what
> could be simpler? Or you just explicitly output a "\n" string.)

One function is simpler than two, so print() with explicit keyword arguments
is obviously simpler AND more powerful.


 

-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to