>>> 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