Data Structure Part 1-d

 

#How does carriage return “\r” work in python
"""
In this Python tutorial, we will learn how does carriage return “\r” work in Python. A carriage return is a special type of escaping character. Many of the Python learners have noticed that \r\n is used in Python. Most of them know the work function of the \n new line in Python. But few of them know about the working function of a carriage return in Python.

So today we will learn what does carriage return “\r” do in Python.
What is Carriage Return in Python or what is \r in Python

A carriage return is nothing but a simple escape character. \n is also an escape character which creates a new line.

Carriage return or \r is a very unique feature of Python. \r will just work as you have shifted your cursor to the beginning of the string or line.

Whenever you will use this special escape character \r, the rest of the content after the \r will come at the front of your line and will keep replacing your characters one by one until it takes all the contents left after the \r in that string.
How does Carriage Return \r work in Python

Let’s understand it with some examples.

"""
print('Python is included in CodeSpeedy')
print('Python is included in CodeSpeedy\r123456')
print('Python is included in CodeSpeedy\r123456789')

Comments