Python is a programming language that allows us to communicate with computers. It is a means to tell a computer what it should do. It’s a language that the computer understands and knows how to process. Let’s take a quick look at what’s new in the Python 3 release.
Learning a programming language means understanding how the language works, its rules, grammar, syntax and semantics. This is similar to the way we learn any language we speak.
Why should one learn Python?
Python is the most popular open source programming language currently. The language is relatively quick to learn, and simple to read and understand. It has intuitive and powerful syntax with a vast array of libraries, and allows scripts to be executed in virtual environments. It is ubiquitous and used for machine learning, Web development, data science, game development, desktop applications, 3D modelling and scientific fields.
Technically, Python is:
- Object-oriented
- Dynamically typed
- Strongly typed
- White-space delimited
- Interpreted
What’s new in Python 3
Python 3 has new keywords, which provide new features. The syntax has been improved, leading to better code patterns. This improves readability and makes expressions easier to use.
New libraries, packages, classes and functions have been introduced. Programmers can directly start using the available modules and libraries, leading to faster development and improved productivity.
It has enhanced support for automated testing, statistical modelling, concurrent processing, asynchronous features, network programming, debugging, etc.
There are improvements with respect to reliability, which eliminate hidden race conditions, enhance security, remove deterministic but surprising behaviours, and generally make creating robust Python applications much easier.
Function | Python 2 | Python 3 | ||
Input | Output | Input | Output | |
print “hi” | hi | print(“hi”) | hi | |
Division | print 7/2 | 3 | print(7/2) | 3.5 |
Bytes | print b‘hello’ | hello | print (b‘hello’) | b‘hello’ |
Unicode | print type(u“hello”) | <type ‘unicode’> | print type(u“hello”) | <class ‘str’ |
Round | round(100.5) | 101 | round(100.5) | 100 |
Input | raw_input(“Enter name”) | Input(“Enter name”) |
Table 1: The differences between Python 2 and Python 3
Key differences between Python 2 and Python 3
Python 3 has intentionally broken compatibility with Python 2. Table 1 lists a few differences between the two versions.
There are tools available to convert Python code from v2 to v3. ‘2to3’ is part of the standard Python library (comes along with the Anaconda package) and is an effective tool for conversion.