Python-print Learning

Source: Internet
Author: User

>>> reply = "" "

Greetings ...

Hello% (name) s!

Your Age squared was% (age) s

"""

>>> values = {' name ': ' Bob ', ' Age ': 40}

>>> Print (reply% values)

Greetings ...

Hello bob!

Your Age Squared is 40

Description

In the default statement, you can directly fill in the% () expression, format the string, in the following format:

%[(name) [(Flags)] [][width][.precision]typecode

Where "name" can be output through a dictionary

==============================================================================

>>> template = ' {0}, {1} and {2} '

>>> template.format{' spam ', ' ham ', ' eggs ')

' Spam, ham and eggs '

>>> template = ' {motto}, {pork} and {food} '

>>> Template.format (motto= ' spam ', pork= ' ham ', food= ' eggs ')

' Spam, ham and eggs '

>>> template = ' {motto}, {0} and {food} '

>>> template.format (' Ham ', motto= ' spam ', food= ' eggs ')

' Spam, ham and eggs '

Description

In. Format, you can output, note that the reference in {}, the number represents the location in format, and the string type represents the reference variable

===============================================

>>> Import Sys

>>> ' My {1[spam]} runs {0.platform} '. Format (sys, {' spam ': ' Laptop '})

' My laptop runs Win32 '

>>> ' My {Config[spam]} runs {sys.platform} '. format (sys = sys, config={' spam ': ' Laptop '})

' My laptop runs Win32 '

Description

You can use keys, attributes, and offsets.

Note that in the PRINT statement, the SYS that is filled in does not represent a program fixed variable and needs to be assigned by Sys=sys

Python-print Learning

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.