Different points of print in Python2 and Python3

Source: Internet
Author: User

Print () method is available in both Python2 and Python3 for printing information, but print is slightly different between two versions

Mainly reflected in the following aspects:

Print in 1.python3 is a built-in function with multiple parameters, while print in Python2 is a grammatical structure;

2.python2 can be printed without brackets: print ' Hello World ', Python3 need bracket print ("Hello World")

In 3.python2, input requires the string to be quoted, in order to avoid reading some of the behavior of non-string types, you have to use Raw_input () instead of input ()

1. In Python3, perhaps the developer feels that print has two identities at the same time, leaving only the identity of the function:

Print (Value1, ..., sep=", end='\ n', File=sys.stdout, Flush=false)
View Code

From the above method prototype can be seen,

①. Print can support multiple parameters, which supports printing multiple strings at the same time (where ...). Represents any number of strings);

②. Sep indicates what character connections are used between multiple strings;

③. End indicates what characters are added at the end of the string, and it is easy to set the print without wrapping, and the print statement under python2.x will wrap after the output string, if you do not want to wrap, just add a "," at the end of the statement. But in Python 3.x, print () becomes a built-in function, and the old method of adding "," does not work.

1>>>Print("python","Tab",". com", sep="')  2 pythontab.com3>>>Print("python","Tab",". com", sep="', end="')#You can print it out without wrapping it.4Pythontab.com
Python2 can be printed without parentheses: print ' Hello World ', Python3 needs braces for print ("Hello World") Python3 print must use parentheses because it is a function.

Different points of print in Python2 and Python3

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.