Python formatted output

Source: Internet
Author: User

1. Print a string
Print " I ' m%s " % ("jihite") I'm jihite
2. Printing integers
Print " I ' m%d years old " % (+) I'm years old
3. Print floating-point numbers
Print " π=%f " % (3.1415926) π=3.141593
4. Print floating-point numbers (Specify the number of decimal places reserved)
Print " π=%.3f " % (3.1415926) π=3.142
5. Specify the placeholder width
Print " name:%8s age:%8d weight:%8.2f " % ("jihite", 62.2) NAME: Jihite age  :      WEIGHT :   62.20
6. Specify the placeholder width (left-justified)
Print " name:%-8s age:%-8d weight:%-8.2f " % ("jihite", 62.2) Name:jihite age   :17       
7. Specify placeholders (only 0 placeholders)
Print " name:%-8s age:%08d weight:%08.2f " % ("jihite", 62.2) Name:jihite age   :00000017 WEIGHT : 00062.20
8. Scientific counting method
' . 2e ' )'2.30e-06'. 2e')'  2.30e-01'

Python formatted output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.