As python supports multiple programming paradigms, like scripting and object orientation, it is often used in wide range of fields like Scientific Calculations and Emulations to Web and Desktop App Development. And this is why Python offers a lot of potential for those looking to pick up an additional programming language.
General Overview
Python was developed in the late 1980s and first published in 1991, authored by Guido van Rossum, who is still very active in the community. It was in 1994 when Python's user base grew, and it became a popular choice among amateur programmers for open source development. During this time, Python went through numerous tweaks and bug fixes. Here is a brief walkthrough of its different versions.
Python 2
Published in late 2000, Python 2 signalled a more transparent and inclusive language development process than earlier versions of Python. Additionally, Python 2 included many more programmatic features including a cycle-detecting garbage collector to automate memory management, increased Unicode support to standardise characters, and list comprehensions to create a list based on existing lists. As Python 2 continued to develop, more features were added, including unifying Python’s types and classes into one hierarchy in Python version 2.2.
Python 3
Python 3 is regarded as the future of Python and is the version of the language that is currently in development. Released in 2008, the focus of Python 3 development was to clean up the codebase and remove redundancy, making it clear that there was only one way to perform a given task.
At first, Python 3 was slowly adopted due to the language not being backwards compatible with Python 2, requiring people to make a decision as to which version of the language to use. Additionally, many package libraries were only available for Python 2, but as the development team behind Python 3 has reiterated that there is an end of life for Python 2 support, more libraries have been ported to Python 3. The increased adoption of Python 3 can be shown by the number of Python packages that now provide Python 3 support, which at the time of writing includes 339 of the 360 most popular Python packages.
Python 2.7
Following the 2008 release of Python 3.0, Python 2.7 was published in July 2010 and planned as the last of the 2.x releases. The intention behind Python 2.7 was to make it easier for Python 2.x users to port features over to Python 3 by providing some measure of compatibility between the two.
Because of Python 2.7’s unique position as a version in between the earlier iterations of Python 2 and Python 3.0, it has persisted as a very popular choice for programmers due to its compatibility with many robust libraries. When we talk about Python 2 today, we are typically referring to the Python 2.7 release as that is the most frequently used version.
Python 2.7, however, is considered to be a legacy language and its continued development, which today mostly consists of bug fixes, will cease completely in 2020.
Key Differences
While Python 2.7 and Python 3 share many similar capabilities, they should not be thought of as entirely interchangeable. Though you can write good code and useful programs in either version, it is worth understanding that there will be some considerable differences in code syntax and handling.
Below are a few examples, but you should keep in mind that you will likely encounter more syntactical differences as you continue to learn Python.
print() function
This is the most well-known change in Python 3. In Python 2, print is treated as a statement instead of a function. So if you want your console to print something on your screen, you will have to do it like this.
>>> print "This is a sample string."
This is a sample string.
With Python 3, print() is now explicitly treated as a function, so to print out the same string above, you can do so simply and easily using the syntax of a function:
>>> print("This is a sample string.")
This is a sample string.
This change made Python’s syntax more consistent and also made it easier to change between different print functions.
Division Operator
In Python 2, any number that you type without decimals is treated as the programming type called integer. While at first glance this seems like an easy way to handle programming types, when you try to divide integers together sometimes you expect to get an answer with decimal places (called a float), as in:
15 / 2 = 7.5
However, in Python 2 integers were strongly typed and would not change to a float with decimal places even in cases when that would make intuitive sense.
When the two numbers on either side of the division ( / ) symbol are integers, Python 2 does floor division so that for the quotient x, the number returned is the largest integer less than or equal to x. This means that when you write 15 / 2 to divide the two numbers, Python 2.7 returns the largest integer less than or equal to 7.5, in this case, 7:
>>> a = 15 / 2
>>> print a
7
>>>
To override this, you could add decimal places as in 5.0 / 2.0 to get the expected answer 2.5.
In Python 3, integer division became more intuitive, as in:
>>> a = 15 / 2
>>> print(a)
7.5
>>>
You can still use 15.0 / 2.0 to return 7.5, but if you want to do floor division you should use the Python 3 syntax of //, like this:
>>> b = 15 // 2
>>> print(b)
7
>>>
Unicode Support
When programming languages handle the string type — that is, a sequence of characters — they usually convert it into numeric equivalent so that computers can understand it. For this, they use a variety of standards and set of rules like ASCII, UNICODE, UTF-8, etc.
Python 2 uses the ASCII alphabet by default, so when you type "Valar Morghulis!" Python 2 will handle the string as ASCII. Limited to a couple of hundred characters at best in various extended forms, ASCII is not a very flexible method for encoding characters, especially non-English ones.
To use the more versatile and robust Unicode character encoding, which supports over 128,000 characters across contemporary and historic scripts and symbol sets, you would have to type u"Valar Morghulis!", with the 'u' prefix standing for Unicode.
Python 3 uses Unicode by default, which saves programmers extra development time, and you can easily type and display many more characters directly into your program. Because Unicode supports greater linguistic character diversity as well as the display of emojis, using it as the default character encoding ensures that mobile devices around the world are readily supported in your development projects.
Conclusion
As someone starting Python as a new programmer, or an experienced programmer new to the Python language, you will want to consider what you are hoping to achieve in learning the language.
If you are hoping just to learn without a set project in mind, you will likely most want to take into account that Python 3 will continue to be supported and developed, while Python 2.7 will not.
If, however, you are planning to join an existing project, you will likely most want to see what version of Python the team is using, how a different version may interact with the legacy codebase, if the packages the project uses are supported in a different version, and what the implementation details of the project are.
I hope you enjoyed this post and learned something new today. If you have any queries or suggestions, please leave a comment below.
Happy Programming!
Comments
Post a Comment