One of those most popular languages in the world, Python has gone through many iterations to match the changing needs of developers and technology trends.
What started as one man’s side project has now advanced to be the fastest growing language in the world. Python is now tool of choice for the next generation of data-driven and AI solutions.
Today, we’ll look at the changes in the different versions of Python from prelaunch to 3.9 and examine the steps that fueled Python’s rise to prominence.
Here’s what we’ll cover today:
Python was made by Dutch programmer Guido Van Rossum in the late 1980s. At the time, he was working on a distributed system called Amoeba at CWI, a computer science research center in the Netherlands. C was the primary language he and the other researchers used.
Van Rossum felt that programming with C was **too time consuming*8. He began to create a new language in his free time that would let him work faster. Little did he know that this side project would eventually become one of the most popular, widespread programming languages in the world.
The appeal of Python has always been its simplicity and unique mixture of C with bash script capabilities. Van Rossum drew heavily on the ABC programming language but included tools for dynamic types and imperative programming as well.
History: As Van Rossum was creating Python, he was reading the script of a popular BBC comedy series called “Monty Python’s Flying Circus”. So he decided on the name Python for his new language because it was unique and mysterious.
Python began to slowly rise in popularity after its open-source release on alt.sources. By the 1990s, Python started to win out over other similar languages like Perl and Ruby due to support by tech companies NIST and Microsoft.
The primary benefits of any Python version are:
Overall, Python is designed to do more work on its own than most languages to allow the developer to focus on their work.
Python 1 launched in 1994 with new features for functional programming, including lambda, map, filter and reduce. It also included features from 0.9 Python, including classes with inheritance, exception handling, functions, and the core data types
Python 1.4 brought its next set of features, such as Modula-3 style keyword arguments and support for complex number operations.
Other version 1 updates included optimizations, background changes, and updates to documentation/licences.
During this period, Perl was the most popular scripting language, and Python was too immature to be used at wide scale. As more developers sought alternatives to Perl, Python seemed the best choice, as it mimics many of Perl’s features. In the world of object-oriented programming, Java was on the rise during this era of Visual Basic and C/C++.
This marked a shift to adopt languages other than C/C++ and opened the door for Python to grow.
Enjoying the article? Scroll down to sign up for our free, bi-monthly newsletter.
Python 2 launched in 2000 with big changes to source code storage. It introduced many desired features like unicode support, list comprehension, and garbage collection. A bit later, Python 2.2 introduced unification of types and classes under one hierarchy, allowing Python to be truly object-oriented.
Around this time, many programmers used to adopt Python as an alternate scripting language. Since Java was dominating in the world of enterprise-sized applications, Python was used in smaller, niche applications.
Even Java developers started using Python to increase their coding speed due to its interoperability.
Python 2.0 introduced the Unicode string data type that allocated 16bit numbers to represent characters instead of standard 8bit strings. This adds 65,000 additional supported symbols from non-latin script languages like Russian, Chinese, or Arabic. It also added support for non-letter characters like emojis.
The syntax for Unicode strings is:
You can also use unicode to encode your own strings to a unique designation. Calling that unique designation later in your code allows you to reference that same encoded string without using additional space or saving it in a variable.
The following writes a unicode string to file and encodes it as
import codecs unistr = u'\u0660\u2000ab ...' (UTF8_encode, UTF8_decode, UTF8_streamreader, UTF8_streamwriter) = codecs.lookup('UTF-8') output = UTF8_streamwriter( open( '/tmp/output', 'wb') ) output.write( unistr ) output.close()
Then, you can read that encoded file later using:
input = UTF8_streamreader( open( '/tmp/output', 'rb') ) print repr(input.read()) input.close()
List comprehensions are used to create new lists from from other iterables. List comprehensions take and return a list, allowing you to trim a list by a certain criteria or to create a new list with newly manipulated elements.
The syntax for list comprehensions is:
new_list = [expression for_loop_one_or_more conditions]
The following shows how you can use list comprehensions to return a new list with only elements that are present in both passed lists.
list_a = [1, 2, 3, 4] list_b = [2, 3, 4, 5] common_num = [a for a in list_a for b in list_b if a == b] print(common_num) # Output: [2, 3, 4]
Python 2.0 overhauls the garbage collection system by switching from a counter-based system to a cycle-based system.
In the old system, each object would contain a counter that records how many other objects are pointing to it. The object was then automatically deleted once that counter reached zero. However, it wouldn’t delete objects that were pointed to but were not accessible, resulting n a memory leak.
Python 2.0 fixes this by periodic cycles that call the garbage collector to delete inaccessible objects. The cycles use additional overhead but reduce the risk of a memory leak. Overhead costs of the deletion cycles have since been reduced due to optimizations.
Python 2.0 also adds support for augmented assignment operators that perform an operation on the chosen variable and return the variable. For example,
a += 1 adds 1 to the value of
a. It is a shorter version of the statement
= a + 1.
The full list of supported assignment operators is
These operators are especially useful when used in conjunction with looping structures.
|Version:||Release Date:||Major Changes:|
|Python 2.1||October 2001||Added support for nested scopes to perform more like other statically scoped languages|
|Python 2.2||December 2001||Unified types and classes into one Python hierarchy to make Python more object-oriented. Also, added generator routines that control the behavior of loops.|
|Python 2.4||March 2005||Added generator expressions for iterator feature, function decorators, and the decimal data type|
|Python 2.5||September 2006||Added the
|Python 2.6||October 2006||Added all backwards compatible 3.0 features, including
|Python 2.7||June 2009||- Minor bug fixes and optimizations. Terminated support for Python 2.|
Practice cutting-edge Python techniques as you prepare for your coding interview. Educative’s Learning Paths let you access all our best content and practice problems from across our entire course library.
Python 3.0 is the biggest change the language has undergone. The main mission of the update was to remove fundamental design flaws with the language by deleting duplicate modules and constructs.
Python 3’s development was steered by the same philosophies as previous versions but also added that for every task “there should be one— and preferably only one —obvious way to do it”.
Removing many duplicate tools unfortunately meant that all previous Python 2 code was not compatible with Python 3.0. Some of the most notable changes are that
input, unification of
unicode, and changes in integer division.
Thankfully, the team at Python created a tool called
2to3 that will review an old Python 2 program and convert much of the changed syntax to Python 3 automatically.
The release of Python 3.0 pushed it into the developer limelight, and it attracted the scientific community, particularly in fields like neuroscience. Once the NumPy library was created in Python, Python became a competitor with R and Matlab, pushing Python into its pedestal as the preferred language for machine learning and data science.
With the rise of big data in the early 2000s, spurred by the 2008 financial crisis, a new need for data automation tools spiked. Many companies adopted Python for its simplicity and powerful libraries. Shortly after, it became the preferred language for managing social-media data.
Between 2012 and 2015, large technology companies like Facebook, Google, and Netflix soon expanded the field of data science and machine learning, using Python as the primary language and R for data visualization. More big-name Python tools like TensorFlow and Seaborn were developed by these companies, making Python the #1 choice for data scientists.
Note: Around 2014, Python had become one of the primary programming languages for beginners. It was even adopted by universities for CS student students and coding camps around the world.
reduce()has been moved from builtins into
exec as *var*is standard over
withis now built in and no longer needs to be imported from
xrange()from Python 2 has been replaced by
range(). The original
range()behavior is no longer available.
In Python 2,
__future__. In Python 3, it has been changed to a built-in function and no longer requires any imports. As it is now a function, you must have all printed arguments enclosed in parentheses,
Old: print "The answer is", 2*2 New: print("The answer is", 2*2)
One notable side effect of this is that you can no longer use an empty
Old: print # Prints a newline New: print() # You must call the function!
print() function does not support the “softspace” feature that internally tracks the state of phrases printed together. In Python 3, two printed phrases will automatically be parsed by a space.
##Py2 print "A\n", "B" "A\nB\n" ##Py3 print("A\n", "B") "A\n B\n"
Apart from these slight changes, the new
print() performs identically. These changes are so straight forward that you can automatically convert all old print statements to functions using the
The Python 2.0 version of
input has been removed and the old
raw_input has been renamed to
input. This means that
input now always returns as a string rather than being evaluated as an expression.
The goal of the change is to remove confusion around the behavior of the two similar
inputs and instead favor the more common use. If you want to use the old functionality, you can instead use
In Python 3, all text content such as strings are Unicode by default. The goal here was to reduce errors caused by mixing encoded and unicode data types in the same program.
You can instead encode strings to bytes using the new immutable
bytes type created with the
bytes() method. There is also a mutable version created using the
bytes() method takes three optional parameters:
source: source to initialize the array of bytes.
encoding: if the source is a string, the encoding of the string.
errors: if the source is a string, the action to take when the encoding conversion fails
The advantage of using bytes is that they hold different forms of data while unicode can only represent text-like data.
For example, you could convert an entire list to bytes using
rList = [1, 2, 3, 4, 5] arr = bytes(rList) print(arr) //Output: b'\x01\x02\x03\x04\x05'
In Python 3, division operations that result in decimals return a float rather than a truncated integer.
In Python 2, the outcome of
5/2 would be
2 because the decimal is automatically truncated to form an integer. Now,
2.5 where the outcome is converted to a float to represent the correct answer. You can still get the truncating behavior if you use the
The desire here is to remove unexpected behavior from unintentional truncation.
|Version:||Release Date:||Major Changes:|
|Python 3.1||June 2009||Added support for ordered dictionaries, which let configuration files be read, modified, and then written back in their original order.|
|Python 3.2||February 2011||Adds the option to restrict modules to specific APIs that will remain stable despite updates. Added the
|Python 3.3||September 2012||Added
|Python 3.4||March 2014||Added the asyncho module that includes support for event loop implementations.|
|Python 3.5||September 2015||Additional support for asynchronous programming by adding awaitable objects, coroutine functions, asynchronous iteration, and asynchronous context managers.|
|Python 3.6||December 2016||Stabilized
|Python 3.7||June 2018||- Added
|Python 3.8||October 2019||- Added “walrus operator” (
|Python 3.9||October 2020||Merge (
In 2019, Python was declared as the fastest-growing programming language in the world, and it now has one of the largest programming communities. This growth is expected to continue following the 2020 lockdowns, which spiked a surge in AI, automation technologies, and data science tracking.
The growth spike is expected to stick around after the COVID-19 pandemic, with more businesses than ever before realizing the benefits of AI and data science. The recurrent sentiment is that businesses cannot risk making a wrong business decision in these fragile times.
This naturally leads many to invest heavily in data science predictive analytics, even in non-tech sectors like tourism, real estate, health care, and more.
While other languages like Rust and TypeScript are trying to capitalize, Python is already well established and proven in these fields. Python is perfectly positioned to grow along with this historic uptick in data-driven innovations.
With more visualization and data analytics tools being released with each version, it seems like Python won’t give up its lead anytime soon.
Join a community of more than 1.3 million readers. A free, bi-monthly email with a roundup of Educative's top articles and coding tips.