[Tutor] Newline

Hugo Arts hugo.yoshi at gmail.com
Sat Dec 4 03:30:30 CET 2010


On Sat, Dec 4, 2010 at 3:04 AM, Rance Hall <ranceh at gmail.com> wrote:
> Ava:
>
> On an old typewriter when you slapped that mechanical arm two separate
> but related things happened.
>
> 1) the page advanced to the next line of text.
> 2) the carriage was returnedt to the beginning of the line of text.
>
> If you were careful about the way you slapped that mechanical arm, you
> could get the page to advance without moving the carriage to the
> beginning of the line.
>
> You would get
>                     stair stepped
>                                         output like this
>
> Now in the computing world, these two separate but related things can
> sometimes still be dealt with individually.
>
> strictly speaking a newline character is the command to move down to
> the next line.
>
> and a return character is the command to go to the beginning of the line.
> On Windows, by convention the newline command does both.
> So you likely won't see the return command much.
> But there is one, and it is used on most non-windows systems.

As a matter of fact, on windows, a newline is encoded in binary as a
carriage return (CR, ASCII code 13) followed by a linefeed (LF, ASCII
code 10). The carriage return is the "return to beginning of line,"
and the linefeed is the "move one line down" that you mention. So in
effect just the ASCII "newline" character *doesn't* do both. However,
python is smart, so when you tell it to print a "\n" escape character,
it prints out both a linefeed and a carriage return on windows systems
(most other programming languages do this as well).

Most older operating systems that predate Unix used this CR+LF
convention as well, because their printing was done on teletypes that
functioned much like actual typewriters. However, you're very unlikely
to come across these systems today, apart from Windows.

Unix systems don't use the carriage return at all, so just a newline
character suffices there to move to the beginning of the next line.
Mac OS (up to version 9, IIRC) actually used just a carriage return,
no newline.

Hugo


More information about the Tutor mailing list