Python formatted output print

Source: Internet
Author: User

1. Commonly used format symbols

% Symbol Usage List:

Format symbols Transformation
%d Signed decimal integer
%i Signed decimal integer, and automatically converts the octal (or hexadecimal) input into decimal
%u unsigned decimal integers
%c Characters and their ASCII code
%s String, formatted by a string conversion of STR ()
%o unsigned integer (octal)
%x unsigned integer (hexadecimal)
%x unsigned integer (16 uppercase characters)
%e Floating-point numbers (scientific notation), lowercase E
%E Floating-point numbers (scientific notation, E instead of e)
%f Floating point number (with decimal point symbol)
%g Floating-point numbers (%e or%f depending on the size of the value)
%G Floating-point numbers (similar to%g)
%p Pointer (memory address of the value printed in hexadecimal)
%n Stores the number of output characters into the next variable in the parameter list
%% Percent Sign

2. Format () Formatting indicator Description

' B '-binary. The number is output as a base of 2. ' C '-character. Converts an integer to the corresponding Unicode string before printing. ' d '-decimal integer. The number is output as a base of 10. ' o '-eight binary. The number is output as a base of 8. ' x '-16 binary. The number is output in 16, and the number of digits above 9 is in lowercase letters. The ' e '-power symbol. Print numbers in scientific notation. Use ' e ' to indicate power. ' G '-general format. The value is output in fixed-point format. When the number is particularly large, it is printed in a power form. ' n '-number. When the value is an integer and ' d ', the values are the same as the ' G ' when they are floating-point numbers. The difference is that it inserts a numeric delimiter according to the locale. '% '-percent. Multiply the value by 100 and then print in fixed-point (' F ') format, followed by a percent semicolon.

3. Specify the alignment of the string for the desired length:

< (default) align Left> Right Alignment^ Middle Alignment= (for numbers only) after the decimal point 4. Python_ Escape Character
Escape character Describe
\ (at end of line) Line continuation character
\\ Backslash symbol
\‘ Single quotation marks
\" Double quotes
\a Bell
\b BACKSPACE (Backspace)
\e Escape
\000 Empty
\ n Line break
\v Portrait tab
\ t Horizontal tab
\ r Enter
\f Page change
\oyy Octal number yy represents the character, for example: \o12 represents a newline
\xyy The decimal number yy represents the character, for example: \x0a represents a newline
\other Other characters are output in normal format

Python formatted output print

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.