Use the new-style string formatting:
print("Total score for {} is {}".format(name, score))Use the new-style string formatting with numbers (useful for reordering or printing the same one multiple times):
print("Total score for {0} is {1}".format(name, score))Use the new-style string formatting with explicit names:
print("Total score for {n} is {s}".format(n=name, s=score))Concatenate strings:
print("Total score for " + str(name) + " is " + str(score))
Pass the values as parameters and
printwill do it:print("Total score for", name, "is", score)If you don't want spaces to be inserted automatically by
printin the above example, change thesepparameter:print("Total score for ", name, " is ", score, sep='')If you're using Python 2, won't be able to use the last two because
printisn't a function in Python 2. You can, however, import this behavior from__future__:from __future__ import print_functionUse the new
f-string formatting in Python 3.6:print(f'Total score for {name} is {score}')
Just pass the values as parameters:
print("Total score for", name, "is", score)If you don't want spaces to be inserted automatically by
printin the above example, change thesepparameter:print("Total score for ", name, " is ", score, sep='')If you're using Python 2, won't be able to use the last two because
printisn't a function in Python 2. You can, however, import this behavior from__future__:from __future__ import print_functionUse the new
f-string formatting in Python 3.6:print(f'Total score for {name} is {score}')