Python built-in functions (50) -- print, pythonprint
English document:
print
(* Objects,Sep ='',End = '\ N',File = sys. stdout,Flush = False)
PrintObjectsTo the text streamFile, SeparatedSepAnd followedEnd.Sep,EndAndFile, If present, must be given as keyword arguments.
All non-keyword arguments are converted to strings likestr()
Does and written to the stream, separatedSepAnd followedEnd. BothSepAndEndMust be strings; they can also beNone
, Which means to use the default values. If noObjectsAre given,print()
Will just writeEnd.
TheFileArgument must be an object withwrite(string)
Method; if it is not present orNone
,sys.stdout
Will be used. Since printed arguments are converted to text strings,print()
Cannot be used with binary mode file objects. For these, usefile.write(...)
Instead.
Whether output is buffered is usually determinedFile, But ifFlushKeyword argument is true, the stream is forcibly flushed.
Note:
1. Used to print and output objects. Use the named sep parameter to determine the delimiters of multiple output objects (default ''), and use the end parameter to determine the end of the output result (default: '\ n '), use the named parameter file to determine the output location (default sys. stdout), use the named parameter fiush to determine whether the output is cached (default: False ).
>>> print(1,2,3)1 2 3>>> print(1,2,3,sep = '+')1+2+3>>> print(1,2,3,sep = '+',end = '=?')1+2+3=?
2. parameters such as sep, end, file, and flush must be passed as named parameters. Otherwise, they will be used as the object to be output.
>>> print(1,2,3,'+','=?')1 2 3 + =?
3. The sep and end parameters must be strings; or the value is None. If the value is None, the default value is used.
>>> print(1,2,3,sep = 97,end = 100)Traceback (most recent call last): File "<pyshell#34>", line 1, in <module> print(1,2,3,sep = 97,end = 100)TypeError: sep must be None or a string, not int>>> print(1,2,3,sep = None,end = None)1 2 3
4. If no parameters are passed to print, only the default value of the end parameter is output.
>>> print()>>> print(end = 'by 2016')by 2016
5. The file parameter must containwrite(string)
Method object.
>>> class A: @staticmethod def write(s): print(s) >>> a = A()>>> print(1,2,3,sep = '+',end = '=?',file = a)1+2+3=?