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

  • Home
  • SEARCH
  • 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 8242543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:12:15+00:00 2026-06-07T21:12:15+00:00

I’m somewhat of a newb to programming with python so please go easy on

  • 0

I’m somewhat of a newb to programming with python so please go easy on me. I’m trying to call the string attribute rjust and also specify precision for a floating point. Here’s the code and sample output (note the 0.00 is not justified to the right):

print '%s: %s %s \tchange: %.2f' % (Instance1.symbol.ljust(5), 
    Instance1.name.ljust(50), Instance1.buyprices.rjust(10), Instance1.val)

OUTPUT:

AXP  : American Express Company                          55.38  change: -1.15  
AXR  : Amrep Corp.                                       6.540  change: 0.00
  • 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-07T21:12:17+00:00Added an answer on June 7, 2026 at 9:12 pm

    This shows an example of how to format your output with two decimal points using the older % formatting method:

    v1 = 55.39
    v2 = -1.15
    v3 = 6.54
    v4 = 0.00
    
    print '%8.2f   %8.2f' % (v1, v2)
    print '%8.2f   %8.2f' % (v3, v4)
    

    the corresponding output:

       55.39      -1.15
        6.54       0.00
    

    Alternatively, you can use the “new and improved” .format() function which will be around for a while and is worth getting to know. The following will generate the same output as above:

    print '{:8.2f}  {:8.2f}'.format(v1, v2)
    print '{:8.2f}  {:8.2f}'.format(v3, v4)
    

    Both sets of formatting directives allocate 8 spaces for your number, format it as a float with 2 digits after the decimal point. You’d have to adjust these values to fit your needs.

    Using this approach to format your output will be easier I think since .format() will give you a lot of control over the output (incl. justifying, filling, precision).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

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.