Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8452471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:30:30+00:00 2026-06-10T11:30:30+00:00

To print strings and numbers in Python, is there any other way than doing

  • 0

To print strings and numbers in Python, is there any other way than doing something like:

first = 10
second = 20
print "First number is %(first)d and second number is %(second)d" % {"first": first, "second":second}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:30:32+00:00Added an answer on June 10, 2026 at 11:30 am

    Using print function without parentheses works with older versions of Python but is no longer supported on Python3, so you have to put the arguments inside parentheses. However, there are workarounds, as mentioned in the answers to this question. Since the support for Python2 has ended in Jan 1st 2020, the answer has been modified to be compatible with Python3.

    You could do any of these (and there may be other ways):

    (1)  print("First number is {} and second number is {}".format(first, second))
    (1b) print("First number is {first} and number is {second}".format(first=first, second=second)) 
    

    or

    (2) print('First number is', first, 'second number is', second) 
    

    (Note: A space will be automatically added afterwards when separated from a comma)

    or

    (3) print('First number %d and second number is %d' % (first, second))
    

    or

    (4) print('First number is ' + str(first) + ' second number is' + str(second))
      
    

    Using format() (1/1b) is preferred where available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do like the way I can treat lists in Python. It does any
If string x contains any letter or number, print that string. How to do
Is there really no way to print an ascii string in assembly to standard
I have a number of strings that represent numbers which use commas or points
Is there a way to write a python doctest string to test a script
How I can do something like this in C++: void my_print(format_string) { vector<string> data;
I'd like to write a doctest like this: >>> print a.string() foo : a
The python docs say: Return the length (the number of items) of an object.
I am currently writing a small application with Python (3.1), and like a good
Is there a function in numpy that determines whether strings should be integers or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.