Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Print multiple arguments in Python

This is only a snippet of my code:
print("Total score for %s is %s  ", name, score)

But I need it to print out:
"Total score for (name) is (score)"

where name is a variable in a listing and score is an integer. This is Python three.three if that allows at all.
by

2 Answers

akshay1995
In Python 3.6, f-string is much cleaner.

In earlier version:

print("Total score for %s is %s. " % (name, score))

In Python 3.6:

print(f'Total score for {name} is {score}.')

will do.

It is more efficient and elegant.
sandhya6gczb
Use one among the following code

print("Total score for {n} is {s}".format(n=name, s=score))


print("Total score for {0} is {1}".format(name, score))

f-string formatting from Python 3.6:
 print(f'Total score for {name} is {score}') 

Login / Signup to Answer the Question.