Python : Comma at the end of print statement

python

Solution

That's because of the `\r`, which is the `carriage return <CR>` character in ascii. It basically resets the cursor to the start of the line.

The comma at the end of that line is because in python 2.7, the `print` statement adds a newline. Using the comma, the newline is not added.

In python 3.x, `print` is no longer a statement but a function. You can provide the `end` keyword-argument to `print()` to determine the ending character, which defaults to a newline, `\n`.

Problem

I've just started learning python from the source `learnjavathehardway`. There was a "fun" code that goes as follows ``` while True: for i in ["/","-","|","\\","|"]: print "%s\r" % i, ``` Now what it does is that at the same place in my console, it prints the different character one by one. (Try it yourself if you did not get what I said) Basically,it prints `/ - | \ |` in quick succession, at the same place. If I remove comma from the end of print statement, it prints each character in a new line. Now I want to know, why is it printing out at the same place? And not one after the other? Thanks

Original source

Related problems