Most terminals understand ANSI escape codes. The relevant codes for this use case:
"\033[F"– move cursor to the beginning of the previous line"\033[A"– move cursor up one line
Example (Python):
print("\033[FMy text overwriting the previous line.")