₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,327,371 members, 8,430,704 topics. Date: Saturday, 20 June 2026 at 10:43 PM

Toggle theme

I Need Your Explanation Here Pls - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingI Need Your Explanation Here Pls (1216 Views)

1 Reply (Go Down)

I Need Your Explanation Here Pls by manuel4real(op): 5:46pm On May 26, 2020
Good day nairalanders. I started learning Python programming language on solo learns a few days ago. While learning I came across this and my question is:

1. Why will someone need to add \n to his program? For instance, print('come\\nhere') gives come\nhere. What's the need for the \n there? Of what importance is It?

Re: I Need Your Explanation Here Pls by incogni2o: 5:52pm On May 26, 2020
\n represents a [i]carriage return [/i]also callled a new line.

Its to make the computer know thier is a new line between the two characters
Re: I Need Your Explanation Here Pls by LSarcastic:
manuel4real:
Good day nairalanders. I started learning Python programming language on solo learns a few days ago. While learning I came across this and my question is:

1. Why will someone need to add \n to his program? For instance, print('come\\nhere') gives come\nhere. What's the need for the \n there? Of what importance is It?
"\n" (backslash n) is basically a newline character. Meaning whenever the program encounters it in a string, the rest of the string is moved to the next line. So, if I run:
print("Hello\nworld"wink

The output will be:
Hello
world

On the other hand, there are cases where you'd like to display "\n" on the screen. Using
print("Hello\nworld"wink
will interpret the character as a newline and you don't want that. The only option is to use another backslash to "escape" it. That means doing
print("Hello\\nworld"wink
instead.

That's why you'll see double backlash in some cases.

Nairaland's parser automatically converts right parentheses to an emoji.
Re: I Need Your Explanation Here Pls by Coder2Client(m): 6:18pm On May 26, 2020
manuel4real:
Good day nairalanders. I started learning Python programming language on solo learns a few days ago. While learning I came across this and my question is:

1. Why will someone need to add \n to his program? For instance, print('come\\nhere') gives come\nhere. What's the need for the \n there? Of what importance is It?
We use \n for next line. If example, you want name, address, number in separate lines you use \n to achieve that.

public class NextLineDemo{
public static void main(String [] args){
System.out.println("Your Name\nAddress\nNumber"wink;

Re: I Need Your Explanation Here Pls by stanliwise(m): 8:47am On May 27, 2020
incogni2o:
\n represents a [i]carriage return [/i]also callled a new line.

Its to make the computer know thier is a new line between the two characters
Basically it means python should end that line and when next python would print it would start on a new line. In It also generates a carriage return characteristics even though it typical don’t mean carriage return.

Carriage return is \r

Incase you wanna know more, google escape characters.

The following is a list of escape sequences.

\n Newline
\t Horizontal Tab
\v Vertical Tab
\b Backspace
\r Carriage Return
\f Form feed
\a Audible Alert (bell)
\\ Backslash
\? Question mark
\' Single quote
\" Double quote
\000 Oct - No one uses Octal unless they have an ICL background...
\xhh Hex number
Re: I Need Your Explanation Here Pls by stanliwise(m): 8:48am On May 27, 2020
LSarcastic:
"\n" (backslash n) is basically a carriage return character. Meaning whenever the program encounters it in a string, the rest of the string is moved to the next line. So, if I run:
print("Hello\nworld"wink

The output will be:
Hello
world

On the other hand, there are cases where you'd like to display "\n" on the screen. Using
print("Hello\nworld"wink
will interpret the character as a newline and you don't want that. The only option is to use another backslash to "escape" it. That means doing
print("Hello\\nworld"wink
instead.

That's why you'll see double backlash in some cases.

Nairaland's parser automatically converts right parentheses to an emoji.
it’s a new line character not necessarily carriage return although it kinda do the two.
Re: I Need Your Explanation Here Pls by LSarcastic: 8:24pm On May 31, 2020
stanliwise:
it’s a new line character not necessarily carriage return although it kinda do the two.
You're right. I'll edit the answer to portray it. Thanks
1 Reply

Any Web3 Research Engineer On Here Pls Let’s ConnectAn Advice Needed Here Pls Can I Get Job As A Graduate With Second Class LowerIT Gurus Here Pls Help Me Answer This Question234

I Need An E-commerce Like JumiaHtml On Linux MachineLearning Ruby