The difference between Python 2 and Python 3 __python

Source: Internet
Author: User

This article lists the differences between Python 2 and Python 3. This is an incomplete list and will be replenished gradually in the future.

1. Print output

Suppose you want to output "HI", let's look at Python 2 and Python 3 in their own notation. The Python 2 notation

Here are two ways to use it.

Print "HI"

Print ("Hi") Python 3 notation

Only one way of writing can be used.

Print ("Hi") 2 input

Let's say you want to enter the number 289 into the variable n, we'll look at Python 2 and Python 3 in their respective ways. the Python 2 notation

There are two ways of writing. The first one is:

Nstr = Raw_input ("Enter a number:") #输入提示 (that is, "Enter a number:") you wrote it.

n = Int (nstr) #raw_input () receives a string, which converts it to an integer

The second formulation is:

n = input ("Enter a number:") the writing of Python 3

The wording is:

NSTR = Input ("Enter a number:") #输入提示 (that is, "Enter a number:") is written by you

n = Int (nstr) #raw_input () receives a string, which converts it to an integer

In fact, Python 3 's input () completes the function of Python 2 's raw_input (). Python 3 does not have the raw_input () function. 3. Divide

Suppose you want to calculate 9 divisible by 2 and store the quotient in variable N. Python 2 and Python 3 are written in a different notation. the Python 2 notation

n = 9/2 #两个整数相除, and the result is the integer Python 3 notation

n = 9//2 #注意有两个斜杠

and the wording:

n = 9/2

The result is 4.5, which is counted as floating-point division.

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.