程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Usage of print() function in Python

編輯:Python

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

1 Common methods

1.1 Print single content

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

 1.2 Print multiple 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 .

2 Default parameters

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 .

2.1 “sep” 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 .

2.2 “end” Parameters

“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 “,”.

2.3 “file” Parameters

“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 .

2.4 “flush” Parameters

“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 .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved