Python built-in functions (--print)

Source: Internet
Author: User

English documents:

print(*objects, sep= ', end= ' \ n ', file=sys.stdout, flush=false)

Print Objects to the text stream file, separated by Sep and followed by end. Sep, end and file, if present, must be given as keyword arguments.

All Non-keyword arguments is converted to strings like str () Does and written to the stream, separated by Sep and followed by end . Both Sep and end must be strings; They can also is none , which means to use the default values. If No objects is given, print () would just write end .

The file argument must is a object with a write(string) method; if it is not present or None , would be sys.stdout used. Since printed arguments is converted to text strings, print() cannot is used with binary mode file objects. For these, use file.write(...) instead.

Whether output is buffered are usually determined by file, and if the flush keyword argument is true, the Stream is forcibly flushed.

Description

1. For object print output. By naming the parameter Sep to determine the delimiter (default ') of multiple output objects, by naming the parameter end to determine the end of the output (default ' \ n '), by naming the parameter file to determine where to output (the default sys.stdout), by naming the parameter Fiush to determine whether the output uses the cache ( 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. Sep, end, file, flush must be passed as a named parameter, otherwise it will be treated as an object that needs to be output.

>>> Print (1,2,3,'+','=? ' )123 + =?

3. The SEP and end parameters must be strings, or none, which means that their default values will be used.

Print (1,2,3,sep = 97,end = +) Traceback (most recent call last):   " <pyshell#34> "  in <module>    print(1,2,3,sep = 97,end= +or not int  Print(1,2,3,sep = None,end = None)1 2 3

4. Do not pass any parameters to print, only the default value of the end parameter will be output.

Print ()print'by'2016

5. The file parameter must be an write(string) object that contains a method.

class A:    @staticmethod        def  Write (s):        print(s)        >> > A = a ()print'+'=? ', file = a)1+2+3=?

Python built-in functions (--print)

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.