What is the difference between python2.7 and 3.5

清浅
Release: 2020-10-13 10:32:47
Original
5850 people have browsed it

The differences between python2.7 and 3.5 are: 1. The results of division are different. python2.7 will round directly, while 3.5 does not round; 2. python3.5 does not support mixing tabs and spaces. In the case of indentation, python2.7 supports it; 3. There are differences between the two libraries.

What is the difference between python2.7 and 3.5

What I will share with you today is the difference between python2.7 and 3.5. It has certain reference value and I hope it will be helpful to everyone.

【Recommended course:python tutorial

(1) Division

a=208,b=5,c=a/b
Copy after login

In python2.7, c will output 41, and it will be rounded directly.

In python3.5, c will output 41.6, without rounding. If you want to round, add an int(a/b) forced conversion

When there is a loop, pay attention to the difference between these two uses

(2) Format

In python3, mixed indentation of tabs and spaces is not supported

(3) Library

In python3, cPickle( python2) has been changed to pickle, and parentheses must be added to print. Without xrange, just use range

items() to replace iteritems()(python2) for places where iteration is required

If In python3, the direct use of

pickle.load(f) “UnicodeDecodeError:'ascii' codec can't decode byte 0x90in position 614: ordinal notinrange(128)”
Copy after login

should be changed to

pickle.load(f,encoding='latin1' or encoding='bytes')
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone.

The above is the detailed content of What is the difference between python2.7 and 3.5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!