Code Learning#PYTHON#8199
Back
Printing newline, carriage return, tab, backspace
Within the string and other similar character streams we can introduce new line, carriage return, tab and backspace etc using escape sequences like \n, \r, \t and \b.
Source Code
Run Output
Notes
- Newline (\n) takes the cursor to newline and also brings it back to first position. This means it gives Newline and Carriage Return simultaneously. In ASCII terms we call it giving LF(Line Feed) and CR(Carriage Return together.
- Carriage Return (\r) takes the cursor back to first position in the same line.
- Tab (\t) is equivalent to 8 space container and it counts the characters already given to fill the space and then fill balance container space with space character.
- Backspace (\b) moves the cursor to one place back.
- The two more characters \f (form feed) and \v (Vertical Tab), are escape sequences of similar nature, but they do not apply for testing on the console. These characters can be useful when string literals are outputted to the printer. \f will place the printer to a new page and \v will give tabbing vertically.
