How \r works, any one give me an example? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How \r works, any one give me an example?

27th Aug 2021, 4:51 PM
Nazma Sheik
Nazma Sheik - avatar
5 Answers
+ 2
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. 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. Ex: print('hello world\r123') Output:123lo world print('hello world\r1234299') Output: 1234299orld (Even space is a character)
27th Aug 2021, 11:50 PM
Khentit Nadji Sabri
+ 2
Thanks Khentit Nadji Sabri It's nice to learn learn something new!
28th Aug 2021, 8:26 AM
David Ashton
David Ashton - avatar
+ 1
But I got the output as hello world123
28th Aug 2021, 9:03 AM
Nazma Sheik
Nazma Sheik - avatar
+ 1
Carriage return is not working in my app
28th Aug 2021, 9:06 AM
Nazma Sheik
Nazma Sheik - avatar
0
Nazma Sheik Yea in some gui editors like here in sololearn but u can run it on console. Use : from __future__ import print_function In ur code to run it properly.
28th Aug 2021, 9:55 AM
Khentit Nadji Sabri