Thursday, February 29, 2024
HomeRecommendedWhat is the difference between Python2 and 3? Which one would you...

What is the difference between Python2 and 3? Which one would you like to learn Python from?

What is Python?

Python is a versatile programming language that is attracting attention in the development of artificial intelligence.

It’s a language that has a philosophy of simplicity, so the syntax is very simple, easy to understand, and easy to read and write. Therefore, it can be said that it is an easy language to learn even for beginners.

In addition to the development of artificial intelligence, it is used in a wide range of development such as business systems, smartphone applications, and web services.

If you want to start learning from now on, Python 3 is recommended

Many programming beginners who are thinking about learning Python may not know which one to learn, Python2 or Python3.

 

If you want to learn Python from now on, I recommend choosing Python3.Here are some reasons why we recommend Python3.

1: There is basically no problem with libraries in Python3

The current major libraries basically support Python3, so you don’t have to worry about libraries after learning Python3.

 

Many new applications developed in Python now use Python3. Therefore, unless you really need Python2, you probably don’t need to choose to learn Python2.

2: Python2 is no longer supported

The latest version of Python2, 2.7, will be out of support in 2020.

Therefore, even if you learn Python2 from now on, you will not receive support. Also, it is expected that what can be done in Python2 now will be migrated to Python3 in the future, so it is recommended to learn Python3 instead of Python2.

Main difference between Python2 and 3

I introduced that if you want to learn Python from now on, it is recommended to learn Python3, but there are many people who do not know the specific differences between Python2 and 3.

There are various differences between Python2 and 3.Here, we will introduce the differences between Python 2 and 3, so please refer to it.

1: print

The difference is that the print statement has been changed to the print function in Python3.

Therefore, if you want to output with Print in Python3, you need “()” as an argument.

 

Specifically, what used to be “print ‘output target'” in Python2 becomes a description method like “print (‘output target’)”.

2: Library

The difference is that Python3 still supports fewer libraries than Python2.

 

Support for many major libraries has been completed, but Python2 still has more libraries. Therefore, if there is a library that you plan to use in advance, it is recommended to check whether it supports Python3.

 

If you can develop with only the standard library, there will be no particular problems with Python3.

3: number

When dealing with numbers in Python3, there is a difference that the decimal point is output.

 

For example, if you create a program that performs numerical calculations such as division like a calculator app and outputs the result, the result displayed as “3” in Python2 will be “3.0” in Python3.

 

For Python2, decimal places are automatically truncated, but for Python3, they are displayed without truncation. If you want to truncate as in Python2, you need to write the division process inside as “(6 // 2)” instead of “(6 / 2)”.

4: int type

The difference is that in Python3 the long type was abolished and is now treated as an int type.

 

In Python3, the long type that existed until Python2 has disappeared, and all are integrated into the int type. Furthermore, with this change, the upper limit of the int type has also been removed, so it is now possible to use the int type for numeric values ​​that were previously handled as a long type.

5: exception syntax

Python3 differs from Python2 in that exception syntax is written differently.

 

When describing exception handling in the source code, the except statement is used, but in Python2, the place where “, (comma)” was used has been changed to “as”.

 

Specifically, the part written as “except Exception, e:” in Python2 has been changed to “except Exception as e:” in Python3.

Why bother with Python2 and 3?

As you can see, there are many differences between Python2 and Python3. Also, since support for Python2 has already ended, it seems natural to learn Python3 if you want to use it.

 

However, there are many cases in which it is difficult to know which one to use.So why bother with Python2 and 3?

Because there are still cases where Python2 is handled

Because of its simplicity, Python is a language that allows users to add functionality through libraries. Therefore, libraries have become a very important element, but some libraries have been discontinued without supporting Python3.

For this reason, there are cases where development can only be done with Python2.

If you want to learn from now, Python3!

Python 2 and 3 are still debated over which one to use.

By all means, why not learn Python3 by referring to the reasons why Python3 is recommended for learning from now on and the differences between Python2 and Python3 introduced in this article.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Most Popular

Recent Comments