How do I add an exclamation mark to a string?

Viewed 43

I am trying to add an ! to a name when it is printed. For example: John!

2 Answers

In Python, you can use + to add strings. E.g.

name = "John"
new_name = name + "!"

If you only want to add it when printing, you can format your output using f-string:

name = "John"
print(f"{name}!")
Related