Python in print() Function to print the specified content . Enter... In the interactive environment “help(print)” Instructions , Can be displayed print() How to use the function , Pictured 1 Shown .
chart 1 print() How to use the function
From the picture 1 It can be seen that ,print() The first argument to the function is value, That is, the content to be printed . adopt print() The method of printing a single content is shown in the figure 2 Shown .
chart 2 Print single content
From the picture 1 It can be seen that ,print() The second parameter to the function is ..., Express print() Function to print multiple arguments , Pictured 3 Shown .
chart 3 Print multiple content
among ,print() Print the a、b、c These three variables .
From the picture 1 It can be seen that ,print() The parameters of the function are in addition to the contents to be printed , also “sep”、“end”、“file” and “flush”, These four parameters have default values , So in print() In the basic use of , There is no need to specify these parameters .
“sep” The parameter specifies print() Function when printing multiple contents , Separator between contents . From the picture 1 It can be seen that ,sep The default value of is space , So figure 3 Printed in a、b and c The values of are separated by spaces .
You can go through the graph 4 To specify the separator .
chart 4 Specify the separator
among , Parameters sep The value of is “,”, Express a、b and c All values of “,” To separate .
“end” The parameter specifies print() Function after printing the contents , What symbol is used to indicate the end , The default value is “\n”.“\n” Indicates a newline symbol , namely print() Function after printing the contents , It'll change the line , Pictured 5 Shown .
chart 5 “end” Output with parameter as default
among , use while Statement loop output i Value , As you can see from the output ,print() Each time the function outputs i The value of , All output “end” The default value of the parameter , Line feed .
Can pass “end” Parameters , Use other symbols to indicate print() Output complete , Pictured 6 Shown .
chart 6 Appoint “end” Output of parameters
among ,print() Functional “end” Parameter specified as “,”, namely ,print() Each time the function outputs i The value of , All output “,”.
“file” The parameter specifies “ Stream object ”, That is, objects similar to files , The default value is “sys.stdout”. Related links 1:sys.stdout, among sys The module provides a series of information about Python Variables and functions of the runtime environment ,stdout yes sys A class file object of the module , Express “ Standard output objects ”, The default is computer screen .
“flush” Parameter specifies whether to force the new flow object , The stream object here refers to “2.3 “file” Parameters ” in file The value of the parameter .“flush” The default value of the parameter is False, Do not force new stream objects .
一、錯誤描述錯誤很簡單,就是xml裡面有非法字符(有的說是編