-2

How do I delete one character of output in Python3?

For instance, I just ran

print("Hello, World!")

But I want my STDOUT to say:

Hello, World

.

I will not accept answers that prints many newlines, but I will accept answers that clear the screen instead.

I am OK with modules, but I don't particularly flavor them.

Number Basher
  • 109
  • 2
  • 10
  • Which character you want to delete? The last? The exclamation mark? You can achieve this by setting a variable and then performing some manipulation with str.replace, re.sub, or similiar methods. – crissal Jun 10 '22 at 06:23

1 Answers1

0

You can assign the output that you want printed to a variable and then just display all except the last character:

to_print = "Hello, World!"
print(to_print[:-1])

If you want to delete the last char you can also re-assign to the variable using the same method:

to_print = "Hello, World!"
to_print = to_print[:-1]
print(to_print)
Hans Bambel
  • 806
  • 1
  • 10
  • 20