I am trying to add an ! to a name when it is printed. For example: John!
Asked
Active
Viewed 480 times
-7
-
This is incredibly well documented all over the internet and is covered in any introductory tutorial/course. There is no reason to ask a question about this. – Michael M. Sep 18 '22 at 21:47
2 Answers
0
In Python, you can use +
to add strings.
E.g.
name = "John"
new_name = name + "!"

actuallyatiger
- 181
- 11
-
1The question has been answered probably millions of times and is basic python skills. It's clearly a duplicate and there's no need to answer it. – Michael M. Sep 18 '22 at 21:49
0
If you only want to add it when printing, you can format your output using f-string:
name = "John"
print(f"{name}!")

bitflip
- 3,436
- 1
- 3
- 22
-
1The question has been answered probably millions of times and is basic python skills. It's clearly a duplicate and there's no need to answer it. – Michael M. Sep 18 '22 at 21:49
-
Does this mean that f-strings should be avoided when not printing? Why? – mkrieger1 Sep 18 '22 at 21:49
-
-
So we can remove "If you only want to add it when printing" from the answer? – mkrieger1 Sep 18 '22 at 21:53
-
@mkrieger1 f-strings can be used for variable assignment as well, using + to add the ! or an f-string gives the same result, but f-strings aren't often used outside print statements since they are slower (in my testing adding is about 19% faster) – actuallyatiger Sep 18 '22 at 22:00