Print multiple arguments in Python

0 votes

This is my code:

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

 I want it to print out:

"Total score for (name) is (score)"

Where name is a variable in a list and score is an integer. Can someone help me with this?

Apr 25, 2022 in Python by Kichu
• 19,040 points
895 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

There are so many ways to do this:

  •  Use %-formatting, you need to pass in a tuple:

            Pass it as a tuple: 

             print("Total score for %s is %s" % (name, score))
  • Pass it as a dictionary:
         print("Total score for %(n)s is %(s)s" % {'n': name, 's': score})
  • Use new-style string formatting:
           print("Total score for {} is {}".format(name, score))
  • Use f-string formatting from Python 3.6:
            print(f'Total score for {name} is {score}')


I hope this helps.

answered Apr 25, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Python

+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,720 points
15,550 views
+1 vote
12 answers
0 votes
1 answer

Multiple line comment in Python

Try this ''' This is a multiline comment. I can ...READ MORE

answered May 31, 2018 in Python by charlie_brown
• 7,720 points
670 views
+1 vote
2 answers

How to print first character of each word in upper case of a string in Python

text = "this is a sample python ...READ MORE

answered Jun 22, 2022 in Python by anonymous

edited Mar 5 12,705 views
0 votes
1 answer

Multiple line comment in python

No, you can simply use triple codes ...READ MORE

answered Jun 28, 2018 in Python by v.liyyah
• 1,300 points
653 views
+1 vote
2 answers

Multiple line comment in Python

Try this ''' This is a multiline comment. ...READ MORE

answered Jul 31, 2018 in Python by Priyaj
• 58,020 points
1,334 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,020 points
1,797 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,020 points
936 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,020 points
2,540 views
+1 vote
1 answer

How is raw_input() and input() in python3.x?

raw_input() was renamed to input() so now input() returns the exact string ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 58,020 points
1,012 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP