What is newlines | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is newlines

l can't understand

17th Dec 2016, 4:50 AM
TEBRIZ ramazanov
TEBRIZ ramazanov - avatar
5 Answers
+ 6
Just like Johnson mentioned: newline {/n} in python works like a enter button in notepad or ms-dos. You can not press enter in middle of python coding, instead you have to use newline for that.e.g ●》》Print("Lord Buddha was born in Nepal.") this will give you syntax error message. but you can generate same output by using newline. i.e ●》》Print("Lord Buddha \nwas \nborn \nin \nNepal.") and the output is Lord Buddha was born in Nepal. I hope it helped you 😃😃
17th Dec 2016, 12:47 PM
‎‏‪‏‪Tarami Nishan‬‏‬‏‎
‎‏‪‏‪Tarami Nishan‬‏‬‏‎ - avatar
+ 5
I won't understand...
17th Dec 2016, 6:10 AM
Ahri Fox
Ahri Fox - avatar
+ 1
Newline, or the newline 'character' "\n", can be put in a string to kick the rest of the string after the "\n" to a new line, almost as if you're pressing enter. So if you have a string like this: "This\nis\na\nstring" When you print it with "print", it will look like: "This is a string" Essentially it substitutes the "\n" with a kick to a new line (and the quotations wouldn't show up either, they're just there to denote what the printed string would look like).
17th Dec 2016, 6:21 AM
Riley Johnson
Riley Johnson - avatar
+ 1
NewLine (AKA "LineFeed") refers to ASCII character number 10. ASCIITable.com would probably be one of the most convenient tables to reference for things like this. When you press Enter on your keyboard within a text editor, you'll notice that your cursor goes back to the beginning of the next line. In reality, this is actually 2 separate steps. It all makes a LOT more sense when you think of it in terms of their original use: Typewriters. When you hit LineFeed, the page was fed through a little bit further, positioning the carriage (main typing section in the middle) where the next line will be, however this LineFeed did NOT realign the carriage to the left of the page; the separate function "Carriage Return" did this (before CR, they had to manually push it back over). Now, when you're typing up a document (assuming not a Unix environment...) and press Enter, your system actually types in a CarriageReturn AND a LineFeed character. The NewLine itself in today's day and age implicitly goes to the beginning of the line anyway, so using both is often unnecessary unless character schema/consistency will be necessary (such as data parsing and such), but for something like console output and logging and such, NewLine alone is just fine. Most languages represent NewLine as \n (important to note that that is a BACKSLASH). CarriageReturn is usually \r
17th Dec 2016, 6:27 AM
Matthew Shephard
Matthew Shephard - avatar
- 1
\n. You work with console (terminal)?
15th Jan 2017, 3:20 AM
Gor Julhakyan
Gor Julhakyan - avatar