Python built-in functions (50) -- print, pythonprint

Source: Internet
Author: User

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.stdoutWill 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=?

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.