The difference between Python2 and python3 (continuous update)

Source: Internet
Author: User

1,print (print)

Python2 version:

print ' A ' outputs a string

Print a outputs a variable

Python3 version:

Print (' a ') outputs a string

Print (a) output a variable

2, input Python3 cancels the input mode of raw_input, and uses input to receive input.

Python2 version:

Raw_input is in the Python2 version, and all input from the user is treated as a string.

Input can only receive integer types.

Python3 version:

No raw_input function, using the input function to receive processing.

What the user is typing is what. For example, you enter a string:

n = input (' Please input somthing: ')

The user input string, ' ABCDEFG ', needs to be quoted in order to represent the string, otherwise the Python interpreter will consider it to be a variable.

User Input Number: 123

User input variable: a

3, list sort by using sort

The list in Python2 can be both a string and a number, then sort using sort, using Ascall code when sorting.

List1 = [' A ', ' B ', 123]
List1.sort ()
Print List1

Run Result: [123, ' A ', ' B ']

The list in Python3 must be a pure number to sort.

List1 = [' A ', ' B ', 123]
List1.sort ()



Operation Result:

Traceback (most recent):
File "c:/users/administrator/pycharmprojects/20180119/index.py", line A, in <module>
List1.sort ()
TypeError: ' < ' not supported between instances of ' int ' and ' str '

Continuous UPDATE!!!

The difference between Python2 and python3 (continuous update)

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.