Home:ALL Converter>What does this stand for?

What does this stand for?

Ask Time:2010-07-25T23:35:03         Author:calccrypto

Json Formatter

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

Author:calccrypto,eproduced 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
Chris B. :

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",
2010-07-25T15:39:08
Scharron :

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).",
2010-07-25T15:39:03
Alex Martelli :

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!-)",
2010-07-25T16:00:30
yy