python- format (%, format, f-string) Input Output +

1- Output Format:%

1.print ( 'My name is% s, height% s cm'% (name, height))

 

 

2.% s -str ();% d- decimal
3. The value passed when the tuples must not list
4. When the specified length:

 

 

Float:

 

 

String:

 

 

2- formatted output: format
characteristics: a string format method

1- filled pit sequence: {} - pit 'names are: {}, Age is: {}' the format ( 'Tom', 16,170).
2- subscript fill hole: 'name is: {0}, age: 2} { '(Tom', 16,170) the format. '
3- fill hole variables:' name is: {name}, age: {age} '(tom' , age = 16 format name =). '

 

 

4- specified length output: l
- {:} 5 - Specifies the output length = 5
l- {String: 5} - Left
2- values - {:} 5 - right justified
use of 2> <- avoid character serial / numerical method for aligning inconsistent
1-> right alignment
2- <left
3- intermediate alignment ^

 

 

Title: The student branch is displayed, the name requires left-aligned, width of 10, the age of information right alignment, width of two front if less than zero

 

 

Supplementary: Python3.6 and later, f-string is not inferior to traditional% -formatting statements and str.format () function in terms of functionality, performance and superior to both at the same time, following a few simple examples

 

 

 

 

Original link: https: //blog.csdn.net/qq_34745204/article/details/82049167

Guess you like

Origin www.cnblogs.com/ceo-python/p/11583995.html