程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The main difference between Python2.x and Python3.x (reproduced)

編輯:Python

Original: https://blog.csdn.net/zylove2010/article/details/79594000

There are big differences between python2.x and python3.x. Except for the big changes in the names of dependent packages, the main differences are summarized as follows:
1) print function
In Python3, the parentheses of the print functionis required, Python2 is optional.

2) The keyboard reads the input
Python3 only retains the input() function, and the input data is all processed as a string; Python2 also supports the row_input() functionstrong>, the input() function in the process of processing the input number, if the input number is enclosed in quotation marks, it will be processed as a string, otherwise it will be processed as a number.

3) Divide
In Python3, the division operation is converted into a floating-point numeric type for processing, and the division operation in Python2 performs the rounding operation.

4) Unicode representation
Python2 data is saved in Unicode encoding format, a string marked with U is required, and Python3 is stored in Unicode encoding format by default.

5) xrange() function
There are range() and xrange() functions in Python2, where xrange() returns the size of the list on demand to save memory usage. In Python3, the xrange() function was renamed to range() function, and slicing is supported in Python 3.2 and later.

6) next() and .next() functions
Python2 supports both functions, and Python3 only supports the next() function.

7) Python2 code to 3 tool: 2to3
The 2to3.py script will usually be installed in the tools/scripts folder.It reads Python2.x source code and applies a series of fixes to turn it into valid Python3.x code; eg: 2to3 -w test.py.


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved