Python3 string Formatting

Source: Internet
Author: User

1, the format of the string:

Output as a new string according to the uniform specifications

2. Method of String Formatting: 1) Format method

Fomat () has two parameter positional parameters and keyword parameters enclosed in brackets {}

# {0}{1} is a positional parameter " {0} love {1}'. Format ("I""you")  'ILove you'
 #  {a}{b} is a keyword parameter  >>>  " {a} love {b}  " . Format (a= " i   ", B="  you   " )   i Love you   " 
" {{1}} ". Format (" do not print " " print ")'{1 }'# The format method is invalidated after enclosing in brackets
2. Formatting operators for strings

Symbol

Description

%c

formatting characters and their ASCII code

%s

formatting strings

%d

formatting integers

%o

Formatting an unsigned octal number

%x

formatting unsigned hexadecimal numbers

%x

Format unsigned hexadecimal number (uppercase)

%f

Format floating-point numbers to specify the precision after a decimal point

%e

Format floating-point numbers with scientific notation

%E

function with%e, format floating-point numbers with scientific notation

%g

Use%f or%e depending on the size of the value

%G

function with%g, depending on the size of the value, use%f or%E

' %c ' %97'a'
' %g  '%1.11111111'1.11111 '

Python3 string Formatting

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.