What is the difference between python2 X and python3 X data types?

Updated on technology 2024-02-23
8 answers
  1. Anonymous users2024-02-06

    Removed the long type, there is now only one integer, int, but it behaves like a version of long

    The bytes type has been added, which corresponds to the octet string of the version, and the method of defining a bytes literal is as follows:

    b = b'china'

    type(b)

  2. Anonymous users2024-02-05

    The main differences with:Difference 1: Python: The source code is not standardized, and there are a lot of duplicates.

    Python : The source code is concise, beautiful and elegant.

    Difference 2: python2: there is an integer int, and longpython3: only an integer int

    Difference 3: python2: range(3) -0,1,2]xrange(3)--iterator

    python3:range(3)--range(0,3) iterable object.

  3. Anonymous users2024-02-04

    If you're a beginner, or you've been exposed to other programming languages before, you probably don't know that when you start learning Python, you will encounter a headache: the version problem!! Is it to learn python2 or python3?

    It's very confusing!

    If you search, you will find that python3 and python2 are incompatible, and the difference is quite large, which version to learn? Let's analyze it for you:

    In fact, Python is one of the most commonly used software on Linux, but most of the current versions of Linux still use Python2, and there are more programs that rely on Python2 on Linux, so it will take a few years for Python3 to replace Python2 and become mainstream.

    The original purpose of designing python3 was to improve python without the baggage of compatibility, but I personally think that the improvement is not drastic enough, some bugs have not been completely improved, and there are many warts who have missed the opportunity to improve, so the syntax incompatibility caused by it is not as many as originally thought.

    People have been exploring for a few years and slowly coming down, and in most cases, they can directly write 2 3 compatible **, and there are also compatible layers such as six available.

    So it's not a problem to learn python2 or python3 first, or it's a problem.

    The current situation is that most of the practical applications do not consider python3 for the time being, and sometimes pay attention to writing compatible with 2 3 **. When writing new with python2 as the mainstay, consider the possibility of migrating to python3 in the future.

    Not. Whether it's python 2 or python 3, you need to pay attention to the other side of the difference: fortunately, these differences are easy to grasp, and there is only one unicode encoding

    Causing a lot of people to be bothered (and a major obstacle to porting many web-related libraries, re-support u'', the situation has improved considerably) Learn python2 still.

    Python3, whether to use python2 or python3 depends on the situation.

    So I recommend:

    1.If you need to use python and learn python in an enterprise, you need to look at the version of python applied by the enterprise.

    3.If you are a university student, then I recommend you to learn Python 3, and by the time you graduate, Python may have become mainstream.

  4. Anonymous users2024-02-03

    If you are a beginner, it is recommended to learn.

    And has been coexisting for a long time. Both versions of Python are being updated, but they are becoming more familiar at the moment. Nowadays, most of the third-party pure class libraries are based on, and most of the books and materials are also available, providing you with a wealth of learning materials.

    This is not an era of reinventing the wheel, and day-to-day development is largely based on libraries. Having a rich library of classes is a sign of a strong language and can greatly develop efficiency.

    And very different, it can be said that they are almost different languages. The current application is not that widespread. For compatibility reasons, many older programs are based on:

    Due to the disruptive nature of Python 3, even relatively new applications will not be used in a hurry. So you should not hesitate to choose.

    The official provides a gadget to convert python2** to python3**, called: If you have python installed, then you must have this file. If you want to experience it, it's a good choice to use it.

  5. Anonymous users2024-02-02

    There is a big difference in architecture, this is done by the inventor of python in the previous company, and now he has changed to another company, and there is a version, which has been changed from the architecture, and it is maintained by the original company, and it is maintained by the current company.

    There is a difference in grammar.

    There is a difference in the default encoding.

  6. Anonymous users2024-02-01

    A lot of language features have been changed, and if you want to know how much it has changed, you can go to the rookie tutorial to see.

  7. Anonymous users2024-01-31

    The differences between the two are as follows:

    1.Performance. Running the Pystone benchmark is 30% slower. Guido thinks there's a lot of room for optimization, both in strings and in shaping operations.

    In order to take the finch to scramble very well optimized results.

    The performance ratio is 15% slower, and there is still a lot of room for improvement.

    2.Encode. By default, the source code file is encoded in UTF-8, which makes the following ** valid:

    China = China'

    print (China).

    china3.Grammar.

    1) Removed <> and used them all! =

    2) Remove and use repr() instead

    4) Integer division returns floating-point numbers, to get the integer result, please use

    5) Add the nonlocal statement. Use noclocal x to directly assign peripheral (non-global) variables.

    6) Remove the print statement and add the print() function to achieve the same function. The same goes for the exec statement, which has been changed to the exec() function.

    4.Words are strings of characters and bytes.

    1) Now there is only one type of str for strings, but it is almost the same as the version of Unicode.

    2) For byte strings, please refer to entry 2 of "Data Types".

  8. Anonymous users2024-01-30

    There will be a lot to sum up, so I carried someone else's answer:

    Here is Zhihu's answer:

    1.print is no longer a statement, but a function, like print'abc'Now it's print('abc')

    However, you can use the from future import print function to achieve the same functionality.

    2.In Python 3, there are no old-style classes, only new-style classes, which means that you don't need to explicitly subclass objects like class foobar(object): pass

    But it's better to judge higher or add. The main difference is that old-style is a classtype type, while new-style is a type type.

    3.It turned out that 1 2 (two integers divided) turned out to be 0, and now it is.

    Python can be modified using the From Future Import Division for all of the above, while noting that replaces the previous operation.

    4.The new string formatting method replaces %

    Error, this method is already in str and unicode since , while python3 still supports the % operator.

    6.xrange renamed to range

    Also changing are a set of built-in functions and methods that return iterator objects instead of lists or tuples, such as filter, map, etc.

    7. !Replaces <

    Python2 is also rarely used < so it's not a big change.

    8.long renamed to int

    Python3 completely abandons the long+int two-inter implementation method and unifies it into int, which supports high-precision integer operations.

    9.except exception, e becomes except (exception) as e

    Only versions of and below do not support this syntax. It is a few feet of digging. Not something new.

    10.exec becomes a function.

    Something like print(), which was preceded by a statement.

    To add simply.

    The main thing is that the library has changed, and the organizational structure has changed a bit. But the functionality hasn't changed. urlparse - such a change.

    The core change it doesn't say, support for bytes and native unicode strings, removal of unicode objects, str for native unicode strings, bytes instead of the previous str This is the most core.

    Other. It doesn't seem to matter much anymore.

Related questions
9 answers2024-02-23

y=(x 2-3x+2) (x 2+2x+1), define the field: x is not equal to -1 move and tidy: >>>More

13 answers2024-02-23

x(x+1)(x+2)(x+3) 8, find the range of x values.

Solution: [x(x+3)][x+1)(x+2)]-8<0x +3x)(x +3x+2)-8=(x +3x) +2(x +3x)-8=(x +3x+4)(x +3x-2)<0 >>>More

18 answers2024-02-23

y= (1+(x 2))+1+(1 (x 2))) let x=tana a (0, 2).

1+x 2=1+tan 2a=1 cos 2a1+1 x 2=1+cot 2a=1 sin 2aso. y=1/sina+1/cosa >>>More

19 answers2024-02-23

Solution: First convert it to a simpler form, and then evaluate the range. >>>More