Python's Common formatted output summary _python

Source: Internet
Author: User

This article summarizes some simple basic output format form, the following words do not say more, to see the detailed introduction bar.

A, print string

>>> print "I ' m%s"% ("Jihite")
I ' m jihite

Second, print integer

>>> print "I ' m%d years old" (%)
i ' M years old

Third, printing floating point numbers

>>> print "π=%f"% (3.1415926)
π=3.141593

Printing floating-point numbers (specify how many decimal places to keep)

>>> print "π=%.3f"% (3.1415926)
π=3.142

V. Specify the placeholder width

>>> print "name:%8s age:%8d weight:%8.2f"% ("Jihite", 62.2) Name:jihite age
:   WEIGHT:  62. 20

Six, specify the placeholder width (left-aligned)

>>> print "name:%-8s age:%-8d weight:%-8.2f"% ("Jihite", 62.2) name:jihite age:17      

Vii. specify placeholders (only 0 placeholders)

>>> print "name:%-8s age:%08d weight:%08.2f"% ("Jihite", 62.2) name:jihite age:00000017  0062.20

Viii. Scientific Counting method

>>> format (0.0000023, '. 2e ')
' 2.30e-06 '
>>> format (0.23, '. 2e ')
' 2.30e-01 '

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.

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.