What does this stand for?
NickName:calccrypto Ask DateTime:2010-07-25T23:35:03

What does this stand for?

What does '\r' mean? What does it do? I have never seen it before and its giving me headaches. It doesnt seem to have any purpose, since 'a\ra' prints as 'aa', but its not the same as the string 'aa'. Im using python 2.6

Copyright Notice:Content Author:「calccrypto」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/3329775/what-does-this-stand-for

Answers
Chris B. 2010-07-25T15:39:08

It's the escape for Carriage Return. On my console, running on Windows, print 'a\\ra' results in ...\n\na\na\n\n\n... getting printed to stdout.\n\nHere's a list of all valid escapes.\n\n\n\\newline - Ignored \n\\\\ - Backslash () \n\\' - Single quote (') \n\\\" - Double quote (\") \n\\a - ASCII Bell (BEL) \n\\b - ASCII Backspace (BS) \n\\f - ASCII Formfeed (FF) \n\\n - ASCII Linefeed (LF) \n\\N{name} - Character named name in the Unicode database (Unicode only) \n\\r - ASCII Carriage Return (CR) \n\\t - ASCII Horizontal Tab (TAB) \n\\uxxxx - Character with 16-bit hex value xxxx (Unicode only)\n\\Uxxxxxxxx - Character with 32-bit hex value xxxxxxxx (Unicode only)\n\\v - ASCII Vertical Tab (VT) \n\\ooo - Character with octal value ooo\n\\xhh - Character with hex value hh\n",


Scharron 2010-07-25T15:39:03

It's an old control character from typewriters.\nIt means \"carriage return\". In this time, when you pressed \"enter\", you were going to the next line, then the carriage went back to the beginning of the line (hence the carriage return).\nThen with computers, different OSes made different choices to represent new lines.\nOn windows, you have \"\\r\\n\" (carriage return + new line).\nOn unices, you have \"\\n\" only (no need to do a carriage return, it was sort of implied by the new line).\nOn old mac OS, you had \"\\r\" only.\n\nNowadays, it's not used except for newlines (or I don't know other usages).",


Alex Martelli 2010-07-25T16:00:30

For me (on a Mac OS X 10.5 Terminal.App, Python 2.6.5):\n\n>>> print 'a\\ra'\na\n\n\nor to give a better example:\n\n>>> print 'longstring\\rshort'\nshorttring\n\n\nIOW, the \\r \"returns the cursor to the start of the line\" (without initiating a new long) so that 'short' \"overwrites\" the beginning of 'longstring'.\n\nThis effect is nice to show to the user a single-line \"current status\" being update during a long operation -- use print '\\rupdate', with a trailing comma to avoid emitting a new-line character, to update the status by overwriting the previous one. Of course you need to ensure each updated string thus shown is at least as long as the previous one (easy by just padding with spaces).\n\nDo note that other responders have noticed different visual effects on their platforms (you yourself have seen \\r disappear without effect, which is unprecedented in my experience) so this nice way to provide updates won't work well on every platform!-)",


More about “What does this stand for?” related questions

What does IFn in Clojure stand for?

In the Java source code for Clojure, I have seen: import clojure.lang.RT; import clojure.lang.IFn; RT seems to stand for "run-time" (although no official source is given in the answer: In the clo...

Show Detail

What does the A stand for in Intellij IDEA?

Does anyone know what the acronym IDEA stand for? I would assume Integrated Development Environment, then maybe Application? Also does Intellij stand for anything?

Show Detail

What does AREL stand for?

What does AREL stand for? I couldn't find what's the meaning of this acronym anywhere.

Show Detail

What does XAP stand for?

What does XAP stand for? is it an acronym? I know what silverlight XAP file contains but dont know what it stands for.

Show Detail

What does LLDB stand for?

What does LLDB ,debugger in xcode, stand for? Is it something like "low level debugger"? Googled it, however couldn't find an answer.

Show Detail

What does boto stand for

What does Boto stand for in the context of AWS? It seems like a random word to choose for an api name. Is it an acronym? I have tried googling around and see no indication of what it could mean.

Show Detail

What does the D in DMCS stand for?

So, I was reading about the mono c# compiler. I know what the purpose of the apps are, but I was just wondering what the abbreviations stand for. (Also what does gmcs, smcs and csc stand for?) If ...

Show Detail

What does . (dot) stand for?

What does . (dot) stand for? For example it is used in sumDigits but I don't understand what it does. toDigits m = loop m [] where loop x y | x <= 0 = y | otherwise = loop (x...

Show Detail

What does osascript stand for?

I am trying this command osascript <<EOD tell "Finder" something etc etc In this command, what does the acronym osascript stand for?

Show Detail

What does JSX stand for?

What does JSX stand for? I am referring to the JSX that is defined as a XML-like syntax extension to ECMAScript, which has become quite popular with the increasing popularity of ReactJS.

Show Detail