Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Is the newline character in ascii/Unicode equivalent to \n in python?

+5 votes
asked Mar 15 by popstar403 (170 points)
Basically, if I check char == "\n", will it return true?

1 Answer

0 votes
answered Mar 18 by Peter Minarik (88,520 points)

Well, that depends on your environment or file.

In Unix based system, the newline character is '\n'.

In Windows based systems, the newline character sequence is "\r\n".

In old MacOS systems, the newline character is '\r'.

Lovely, isn't it? :D

Your code would only work in Unix based systems (All the Linux distributions, FreeBSD, modern MacOS etc) and finding the last character in Windows (but not finding the '\r', probably assuming it's part of the valuable text).

You can find out a bit more about newline representations here.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...