Python string format note

Source: Internet
Author: User

Chinese name: string formatting

Function:

    1. One parameter can populate multiple format characters

>>> "Hello {}". format ("LSL")

Hello LSL

{} expression grammar:

Replacement_field :: = "{" [field_name] ["!" conversion] [":" format_spec] "}"

The Field_name name descriptor, which can be a name, location, property.

Properties, which I am interested in, so that you can populate multiple formats with just one pass.

The FORMAT_SPEC format descriptor, which can be the padding + alignment number + format.

%xxx, which is basically the same as the format descriptor.

Print ("Helllo%-10s", "33")

Format: Inherits the form of D s F, which is traditional print.


Example
in []: "Hello {people.name:*>10}". Format (PEOPLE=P)
OUT[38]: ' Hello *******LSL '

Https://docs.python.org/2/library/string.html#string-formatting

Http://www.jb51.net/article/63672.htm

Python string format note

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.