Python printing text after printing a variables
96,025
Solution 1
Just include the hitpoints:
print('The enemey gets hit for %d hitpoints' % damage)
The formatting operator %
is very powerful, have a look at all the placeholder options. It is, however, intended to be phased out in favor of str.format
:
print('The enemey gets hit for {} hitpoints'.format(damage))
Alternatively, you can convert the value of damage
to a string, and concatenate strings with +
:
print('The enemy gets hit for ' + str(damage) + ' hitpoints')
Solution 2
Looks much nicer this way. ;0)
damage = 10
print(f'The enemey gets hit for {damage} hitpoints')
(for python 3.6 & above)
Solution 3
Just add hitpoints
to your string:
print('the enemy gets mutilated for %d hitpoints!' % damage)
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on July 05, 2022Comments
-
Admin almost 2 years
So I wanna print some text after i print my variables like this:
print('Blablabla' var ' blablabla')
Right now it looks like this:
print('The enemey gets hit for %d' % damage)
I wanna print the word "Hitpoints" after I've printed the damage variable.