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 8388687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:31:34+00:00 2026-06-09T18:31:34+00:00

I use python 2.6 and have read many links about removing new line from

  • 0

I use python 2.6 and have read many links about removing new line from ‘print’ but cannot find example of usage together with formating using modulo sign (%). In my program I am trying to write in a loop line of calculated data but each line data comes from different calculations:

while loop
    ... calulating value1 and value2
    print ('%10d %10s') % (value1, value2)    [1]
    ... calulating value3 and value4
    print ('%7s %15d') % (value3, value4)    [2]
    print #this is where newline should come from

So I would like to get:

value1 value2 value3 value4
value5 value6 value7 value8
...

Basically this approach keeps readability of my program (each real line has over 20 calculated positions). The opposite way would be to concatenate all data into one, long string but readability could be lost.
Is it possible to remove newline using “print () % ()” syntax as in [1] and [2] ?

  • 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-09T18:31:35+00:00Added an answer on June 9, 2026 at 6:31 pm

    If you add a comma (,) at the end of the statement, the newline will be omitted:

    print ('%10d %10s') % (value1, value2),
    

    From http://docs.python.org/reference/simple_stmts.html#print:

    A '\n' character is written at the end, unless the print statement ends with a comma. This is the only action if the statement contains just the keyword print.

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

Sidebar

Related Questions

I have a Python script that makes use of 'Print' for printing to stdout.
I read this: python singleton into multiprocessing but I didn't find the solution of
I have a simple Python program which uses a read-eval-print loop to read user
I use python 2.7. I have data in file 'a': myname1@abc.com;description1 myname2@abc.org;description2 myname3@this_is_ok.ok;description3 myname5@qwe.in;description4
You have a Python class which needs an equals test. Python should use duck-typing
i have an issue i could use some help with, i have python list
I have a Python Facebook project hosted on Google App Engine and use the
I have 2 python scripts https://gist.github.com/2233477 . rsgen.py generates random inputs for use in
I am learning how to use sqlite3 in python. I have a simple table
I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create

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.