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 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
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)”
should be changed to
pickle.load(f,encoding='latin1' or encoding='bytes')
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!