Py
Py
Py
You
can add a new line at the start of the file and then modify the second line. See
print(mg1)
You can see that the output is the same as we had before. So, what is different
here? I have added a variable named mg1 in the code. Every variable in Python
holds a specific value. This is the information that is associated with the same
The addition of a variable causes a bit more work for the Python interpreter.
When the interpreter processes the first line of code, it tends to associate the text
with the message of the variable. When it gets to the second line, it usually prints
the value associated with the message toward your computer screen. Let’s
print(mg1)
print(mg1)
This means that you can always change the value of the variable in your program
at any time. Also, Python keeps track of every change in the current value of the
variable.
Naming Variables
When you are working on variables in Python, you have to adhere to several
guidelines and rules. Breaking these rules will definitely cause certain errors.
Different guidelines will help you write code that’s easier to understand and
read. However, you need to be sure that you follow a set of rules when naming
them.
The first rule is that the names of variables should only contain numbers, letters,
Python Version History: How Python has changed over the years
Ryan Thelin
editor-page-cover
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.
Python 1
Python 2
Python 3
Become a Python Developer the fast way with hands-on, text-based lessons.
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.
Dynamically Typed, Python determines types at execution. No need to declare variables and data types.
Open-Source, Python is free to use and develops quickly due to community input.
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 list, dict, str.
Python 1.4 brought its next set of features, such as Modula-3 style keyword arguments and support for
complex number operations.
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
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.
Unicode
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.
u`unicode string`
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.
import codecs
(UTF8_encode, UTF8_decode,
output.close()
print repr(input.read())
input.close()
List Comprehension
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 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]
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.
Augmented Assignment
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 +=, -=, *=, /=, %=, **=, &=, |=, ^=, >>=, and <<=.
These operators are especially useful when used in conjunction with looping structures.
Python 2.1 October 2001 Added support for nested scopes to perform more like other statically
scoped languages
Python 2.2 December 2001Unified 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 with statement that encloses code within a context
manager.
Python 2.6 October 2006 Added all backwards compatible 3.0 features, including typeError, bin(),
and _complex_(). Switched from SourceForge Issue Tracking to Roundup. Also, optimized the with
statement.
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
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 print is now a built-in function, removal of
the Python 2 input, unification of str and 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.
It was around this time that Pandas, Scikit-learn, and Matplotlib were developed to meet this demand.
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(): reduce() has been moved from builtins into functools. However map() and filter() remain built-
in.
Old feature removal: old-style classes, string exceptions, and implicit relative imports are no longer
supported.
Exception handling: exceptions now need the as keyword, exec as *var* is standard over exec, *var*.
with statement: with is now built in and no longer needs to be imported from __future__.
range: xrange() from Python 2 has been replaced by range(). The original range() behavior is no longer
available.
Print Function
In Python 2, print was a statement that had to be imported from __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, print("printed").
For example:
One notable side effect of this is that you can no longer use an empty print statement to create a new
line.
Further, the 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
"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 2to3 tool.
raw_input to input
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 eval(input()).
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 bytearray() method.
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 bytes():
rList = [1, 2, 3, 4, 5]
arr = bytes(rList)
print(arr)
//Output: b'\x01\x02\x03\x04\x05'
Integer division
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, 5/2 equals 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 // operator, 5//2.
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 argparse module to replace optparse and the futures library for
concurrent programming.
Python 3.3 September 2012 Added yield from expression for generator delegation. Readded
explicit unicode declaration support to ease transition from Py2 to Py3. Simplified error catching by
removing the requirement to name a specific error type. All errors can now be caught using OSError.
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 2016Stabilized asyncho module with additional features, syntax,
optimizations, and bug fixes. Added support for asynchronous generators and compressions. Added f-
strings, which include expressions evaluated at runtime.
Python 3.7 June 2018 - Added async and await as reserved keywords. Also, added breakpoint()
method, which drops you into the debugger at the call site. Annotation evaluations can now be
postponed until runtime rather than at definition to avoid scope errors.
Python 3.8 October 2019 - Added “walrus operator” (:=) that allows you to assign value to
variables as part of a larger expression. Enabled positional-only arguments that allows you to specify
that a parameter must be noted by position rather than keyword. Added support for f-string specifier =
to allow more control over how the f-string is presented.
Python 3.9 October 2020 Merge (|) and update (|=) added to dict library to compliment
dict.update() method. Added str.removeprefix(prefix) and str.removesuffix(suffix) to easily remove
unneeded sections of a string.
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.
WRITTEN BY
Ryan Thelin
Join a community of 675,000 monthly readers. A free, bi-monthly email with a roundup of Educative's
top articles and coding tips.
Full Name
Subscribe
LEARN
Courses
Assessments
New
Blog
Pricing
Free Trial
New
For Business
CodingInterview.com
SCHOLARSHIPS
For Students
For Educators
CONTRIBUTE
Become an Author
Become an Affiliate
LEGAL
Privacy Policy
Terms of Service
MORE
Our Team
Careers
Hiring
For Bootcamps
Quality Commitment
FAQ
Press
Contact Us
soc2
We use cookies to ensure you get the best experience on our website. Please review our Privacy Policy
to learn more.
Got it!