Introduction to Python. The who, what and why of Python | by Aaron S | Towards Data Science

So you’ve decided to start programming and may have heard Python is a popular language to start with. It’s important to know what the language is about before diving in. In this article, we will be taking you through what Python is, what it can be used for and you will understand a bit about how Python works under the hood.
To be able to understand how python fits in the landscape of programming languagesWhen you would use python over other programming languagesWhat can you do with PythonThe potential weaknesses of a Python project
To be able to understand how python fits in the landscape of programming languages
When you would use python over other programming languages
What can you do with Python
The potential weaknesses of a Python project
You may have heard of Python and how many people are using it. It is hard to give a complete answer to why something is so popular, but we can attempt to give you an understanding we think python has taken off in the last 10 years.
First python’s readability, python as a programming language is meant to be readable. That is the code you use can be understood without too much effort on the part of the reader. This becomes massively important when you have a piece of software with 100,000’s of lines of code bundled up, having something that can be followed lowers the barrier for entry to those wanting to learn it.
With python, the learning curve to get up and running writing code with python is quite short! This makes it perfect as a first language to learn.
As a programming language, it is programming paradigm agnostic, by this, we mean that there are different ways to program and python allows you this flexibility. You may have heard of the terms such as functional and objective orientated programming, if not don’t worry! Needless to say, python does not dedicate how you program.
Productivity is another highlight of Python, programs that are written in other languages like C++ and Java are often much larger (sometimes up to 3 times larger!) and require intermediate steps to run the program. Python programs in comparison run immediately. This means prototyping something in Python takes a fraction of the time. Python also runs on all operating systems, so whatever your preference you are able to start coding.
Python also has a lot of useful built-in functions straight off the bat and can often make the experience of writing code much easier. This may not be an immediate detail that you think about or have a large impact in the short term but the more you use of a language the more you start to understand the benefits and disadvantages when writing programs. You will start to love python’s built-in functions when you understand how difficult in other languages to do the same function.
Based on the popular forum StackOverflow, their survey showed that of 44,000 programmers interviewed 44.1% are using python in their day to day activities. You can also see that over a course of 6 years the number of python questions on StackOverflow forum has increased exponentially, this is often a marker how many people are learning this language.
Now having an understanding of the why Python is popular we can start to understand what it is. The Python language was created by Guido Van Rossum between 1985 and 1990, Guido is known to have named the language after Monty Python! Guido was clearly a fan! Python is a general-purpose programming language which has several properties unique to it which are outlined below.
{   name: 'Aaron' }
Everything in the python code is an object, this is what is called a programming paradigm. As an overview, an object is a way of representing data and relationships between data. Python is implicitly object-based, and this means there are specific ways of representing relationships between data and how to manipulate that data. Objects are also a clear way to structure programs into boxes of functionality and being able to interact with those boxes in a scalable way.
To know what this means we have to scale out from python for a second. Programming languages can be split into two different types, languages that need to be compiled and those that are interpreted.
Compiled languages take the code written and requires it to be converted into code that hardware can use. This converted code is called machine code and makes your program able to be run by the computer hardware before actually running your program.
Interpreted languages like Python reads the code line by line and evaluates and converts this code into machine code on the fly. This conversion happens all under the hood without you having to think about it. The code development time because of this is shorter than having to convert code into something that machines can read first before running a program.
This means that objects are held within memory at the run time of your code and there is no need to declare what data types you’re using before running your programs, unlike other languages. This is partly why programs in C++ and Java are much larger than python. It, however, also means that error messages do not occur until you start to run your program. This can lead to some trouble if you’re not careful with your code!
This means that it enforces what type of data you’re using, so you can’t mix operations with different data types. Python will throw an error if you attempt to do this. The alternative to this would be that you have to define your types of data as you do in other languages. This can increase the time you write code by large amounts.
So now you know that python is object-based, it is an interpreted language that is dynamically and strongly typed. A bit of a mouthful but you can start to see how other languages differ when you have this vocabulary in mind.
Knowing what python is and why it’s popular is important but what can you actually do with it ?!
We mentioned that python is a general-purpose programming language. So here is a not so complete list of tasks suited for python and some of the libraries used to create programs.
Automating task i.e renaming files, updating spreadsheets (Built-in modules)Web Development (Flask, django)Data Science and Database programming (Pandas)Machine Learning (TensorFlow, Keras, Scikit-learn)Bio-informatics (Biopython)Network ProgrammingRobotics and hardware programming (Arduino)FinanceNumerical and Scientific Programming (Numpy, SciPy)
Automating task i.e renaming files, updating spreadsheets (Built-in modules)
Web Development (Flask, django)
Data Science and Database programming (Pandas)
Machine Learning (TensorFlow, Keras, Scikit-learn)
Bio-informatics (Biopython)
Network Programming
Robotics and hardware programming (Arduino)
Finance
Numerical and Scientific Programming (Numpy, SciPy)
You may be asking how can it all do this ?! Well, Python has a very rich support system. There are many programmers who have helped develop modules that can be used with python to do all sorts of different types of work, ranging from robotics, bio-informatics to artificial intelligence. If you’re interested in the variety of what python can do, please consult the link here for a very detailed list of the libraries python has available.
There is a huge amount of support in the Data Science universe for python and it is the main programming language to do this type of research. So if you are interested in the data science arena, then python is the language you should consider learning it.
In addition to the above list of libraries available to python below is a list of the small offering of the companies today that are using python. This goes to show how effective python can be as a language and why it may be worth your while to understand it!
Now in this article, we have painted a picture of python being this wonderful language that everyone should learn. However, it is not suited for every occasion and does have some limitations.
Python doesn’t have great mobile development capabilities and lacks the 3rd party library support currently! The two popular frameworks are Kivy and Beeware, but they are still not optimised for heavy user usage currently. Python is memory consumptive and applications using python presently drain the battery much faster than say mobile applications developed in Java.
With these two points in mind, mobile application development has not taken off yet with Python however this is a space that will change with time.
Python can be slow for many reasons but as an overview, it’s mainly because of its dynamic nature and versatility of programming paradigms.
Python, unfortunately, runs only one operation at one time, this is called the global interpreter lock (GIL). Most modern applications have multiple processes going on at once and this means that python can be difficult to scale up in application size. The global interpreter lock concept is a detailed subject in python and you don’t need to know the details other than to be aware that it exists.
One of the other reasons relates to the interpreted part to the language itself, it automatically converts code at runtime which takes time to do, unlike compiled languages. Yes with a compiled language you have to convert the code, but once that code is converted, it can be quite fast.
All programs have to manage memory, that is how do we store the code to work with it whilst running a program? Now because everything in python is an object this can actually be quite consumptive to run programs with. Every single object consumes memory. This may not matter if your scripts are small and the program isn’t mission-critical however if your project is ambitious and becomes larger it can cause real problems later down the line. This is a consideration when your application becomes used by many users and the demands of the application become much greater
We mentioned that python is dynamically typed, which means that errors only occur when we run the program. This is in comparison to a compiled program which will always run once it’s correctly compiled. This dynamic typing means that it can be annoying having to make small changes over and over again if you’re not careful! Be mindful of this when you first start on your python journey.
We have talked about how quick and easy python is to prototype and it’s general-purpose nature means it’s well suited for many tasks.
You can imagine that Python could be optimised from a performance perspective, but if performance is absolutely mission-critical, python is probably not the language to be using! It is however great for prototyping applications quickly and testing it out with user-bases, this is why it’s so valued within the start-up community.
Python is fine for small graphical user interface (GUI) programs, but anything that you are developing that relies heavily on the need for being able to interact with a GUI, then python is probably not the language of choice. For that matter, it would not be wise to try say create an operating system based on python for this matter, when speed is absolutely necessary.
Noting the above, you can imagine anything that involves hardware that there’s going to be a relied on it would probably not be in your best interest to rely on python.
To conclude, Python is a general-purpose programming language with a huge 3rd party library support. It can be used to automate tasks up creating neural networks for artificial intelligence research. It is flexible and readable with a short learning curve, as well as being easy to start creating real scripts whilst still learning.
Its main downfall is performance speed and so programs that are mission-critical you can imagine that this may not be the language to use if you plan on maintaining large scale projects.
It is useful for prototyping ideas and getting something off the ground easily, this is why there are many startups using python to get their projects off the ground.
What is the difference between an interpreted language and a compiled language?
What is dynamically typed mean?
What does strongly typed mean?
What are the weaknesses of Python?
When would you consider using another language other than Python?
This article was first published on CodeMD, here. We at CodeMD are passionate about bringing Python to healthcare professionals. Please come join us if you’re interested in Healthcare and Python.
codemd.co.uk
I’m a practising medical physician and educationalist as well as being a web developer.
Please see here for further details about what I’m up to project-wise on my blog and other posts. For more tech/coding related content please sign up to my newsletter here
I’d be grateful for any comments or if you want to collaborate or need help with python please do get in touch. If you want to get in contact with me, please do so here asmith53@ed.ac.uk or on twitter.