How can i overwrite the previous "print" value in python?
print "hello"
print "dude"
print "bye"
It will output:
hello
dude
bye
But i want to overwrite the value.
In this case the output will be:
bye
How can i overwrite the previous "print" value in python?
print "hello"
print "dude"
print "bye"
It will output:
hello
dude
bye
But i want to overwrite the value.
In this case the output will be:
bye
Best way is.
Write
After print.
Example:
Output: bye
As an alternative to
you can also use
The value
100
can be changed to what you requireCheck this curses library, The curses library supplies a terminal-independent screen-painting and keyboard-handling facility for text-based terminals. An example:
x.py:
run it
python x.py
You can use
sys.stdout.write
to avoid the newline printed byprint
at each call and the carriage return\r
to go back to the beginning of the line:To overwrite all the characters of the previous sentence, you may have to add some spaces.
On python 3 or python 2 with
print
as a function, you can use theend
parameter:Note that it won't work in IDLE.
In
Python 3
:Output: