A formatted output string methods:
Used string formatting symbols:% s --- with str () function converts a string
% D --- converted to signed decimal
% F --- converted to floating point (the fractional part of the natural cut-off)
% X --- converted to an unsigned hexadecimal number
Specifies the length of the printing: the same numbers and strings
1 -% 5d right-aligned, left space if less than
2 - -% 5d left-aligned, lack of space if the right
3 - complement 0% 05d
Hex:% # x # to add a 0x
Decimal: float default is 6; specify the number of decimal places to retain ----% .3f ---- were rounding;
% 6.3f ---- 6 represents the total length (including . )
% 08.3f ----- fill 0
Two methods formatted output string: the format () {} fixed ----
1-- order to fill the pit may have a multi-element, the element can not have less
Such as: print ( '{} is the name, age {}' format (name, age).)
2 - subscript filled pit
Such as: print ( 'name is {1}, Age is {0}' format (name, age).)
3 - Variable filled pit
Such as: print (. 'Name {name}, age {age}' format (name = 'tom', age = 23))
You can also specify the length of the output:> a right-aligned <Left center aligned with ^ XOR
Such as: print ( 'name is: {:> 9}, Age is: {:> 9}' format (name, age).) The total length of 9 is right-aligned, the left space if less than
print ( 'name is: {: <9}, Age is: {: <9}'. format (name, age)) The total length of 9 are left-aligned, lack of space if the right
print ( 'name is: {: 0> 9}, Age is: {: 0> 9}'. format (name, age)) The total length of 9 are right-aligned, the left complement deficiencies 0
print ( 'name is: {:} ^ 9, age: {: ^ 9}' format (name, age).) The total length of 9 are aligned on both sides of the intermediate space if less than
After Python3.6, also can be written:
print (f 'name: {name}, age: {age}')
Written on the path: Three
①fileDir = 'C:/test'
②fileDir = 'C: \\ test' backslash generally occur in pairs, to avoid ambiguity, such as \ n, \ t
③fileDir = r'C: \ test 'r to unescape
Character input terminal:
INPUT () ---- console input terminal
1-- return value - str
2 - If the arithmetically obtained value ---- int (), float ()
3 - the end user's input is a carriage return ----- not hit Enter to die, etc.
input Built-in functions: as num = input (Enter your student number :)
int built-in functions: as name = int (input ( 'Please enter your name:'))