How To Use Python Carriage Return?

Last Updated on August 23, 2021 by admin

There may be situations where you desire to return to the beginning of the same line. This article will help you understand the concept of Python carriage return or Python\r.

What is a Python carriage return (\r)?

It helps to move the cursor to the beginning of a line without moving the cursor to a new line.

How to use carriage return?

It speaks for any type of “\r” that can be used in Python.

  1. Only use Carriage Returns in Python:

In this example, the program between strings only uses carriage returns.

 	String = 'My Website Lateral \ Resolution.'
 	String

Output:

The solution is the la trace.

Description:

  • First, I got the input string as a string.
  • I applied \ r between the strings.
  • \ r Moves the cursor to the beginning, and “Solution” carries eight characters. The first eight characters are deleted, and the solution is printed.
  • You can check the output for better understanding.
  1. Using Carriage Returns in Python with New Line Characters:

The string program uses “\ r” with a new line character (\ n) in this example.

 
String = 'My Website Lateral \ r \ n Solution.'
String = 'My Website Lateral \ n \ r Solution.'
anyvar = 'My Web \ n SiteLatracle \ r Solution.'

Output:

  • My website is Lateracle
  • Solution
  • My website is Lateracle
  • Solution
  • My web
  • Solution Lateral

Description:

  • First, I got the input string like a string.
  • Then, I applied \ n and \ r to multiple places in the string.
  • \ n For row breaks.
  • The first two strings have \ r before and after \ r. Therefore, the output is output with a line break.
  • In the last string, \ n has been changed because it comes first after “sites” and contains eight characters like a solution.
  • So, you can see the output.

Read More: 3 Best Ways to Exit a Python Program

Leave a Comment