#python Str.format method is used to format the output of a string.

Source: Internet
Author: User

#python Str.format method is used to format the output of a string.
# ". Format ()
Print (' {0}+{1}={2} '. Format (+/-))
#1 +2=3 The numbers in curly braces in the visible string correspond to several parameters of format.
Print (' {}+{}={} '. Format (+/-))
#1 +2=3 If you omit a number, you can get the same output. But the replacement order by default follows [0],[1],[2] ... For
#
Print (' {1}+{0}={2} '. Format (+/-))
#2 +1=3 If you replace {0} and {1}, the result is the same.
Print (' {0}\tlove\t{1} '. Format (' I ', ' you! '))
#I Love ! output string
Name= ' Xiaoming '
Age=23
Print (' {0}\tis\t{1}\tyears old this year! '). Format (name,age))
#xiaoming is at years old!
Print (' {0:.4} '. Format (1/6))
#0.1667 decimal point precision matched to 4 bits
Print (' {0:8}:{1:8} '. Format (' name ', ' Xiaoming '))
#name : xiaoming width configuration
#
Print (' {0:<7.3} ... '. Format (1/3))
#0.333. #精宽度控制 (width left), the same as ' > ' for the right, ' ^ ' is centered. The symbol is very image.

The

#python Str.format method is used for formatted output of strings.

Related Article

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.