Hi! Please take a moment to think about this question:
How is Python applied in real-world scenarios?
If you are learning Python and you want to know the answer, then this article is for you.
Having a clear idea of the applications and vast potential of this programming language will give you the motivation that you will need throughout your journey.
Let's begin! 🔅
Python in Real-World Scenarios
Python is used in virtually every industry and scientific field that you can imagine, including:
- Data Science.
- Machine Learning.
- Web Development.
- Computer Science Education.
- Computer Vision and Image Processing.
- Game Development.
- Medicine and Pharmacology.
- Biology and Bioinformatics.
- Neuroscience and Psychology.
- Other areas such as robotics, autonomous vehicles, business, meteorology, and graphical user interface (GUI) development.
This article covers a wide range of applications of this programming language in these industries with examples, use cases, and Python libraries. Let's start with the applications of Python in data science.
🔹 Data Science: Analysis and Visualization
Perhaps one of the most popular applications of Python is data science. The power of the Python libraries developed for data analysis and visualization is amazing. Let's see why.
Data Science Applications
With a Python data visualization library, you can create a wide variety of plots and visual representations, such as:
- Lines, Bars, and Markers.
- Images, contours and fields.
- Subplots, axes and figures.
- Statistics (Box Plots, Bar Charts, and Histograms).
- Pie and polar charts.
- 3D Plots.
- and more!
You can add text, labels, annotations, color, shapes, collections, animations, and interactivity to your plots depending on the package or library that you choose to work with.
💡 Tip: You can see some examples of data visualizations generated with Python in the image above.
Libraries and Packages
Let's see some of the most popular packages and libraries to work with Python in data science:
Python for Data Analysis
- NumPy: this package is described as "the fundamental package for scientific computing with Python". According to the official website of this package, "nearly every scientist working in Python draws on the power of NumPy."
- Pandas: is "a fast, powerful, flexible and easy to use open source data analysis and manipulation tool."
Python for Data Visualization
- Matplotlib: is "a comprehensive library for creating static, animated, and interactive visualizations in Python." If you are curious about what you can do with this library, check out the example gallery.
- Seaborn: is "a Python data visualization library based on matplotlib." If you are curious about what you can do with this library, check out the example gallery.
- ggplot2: is "a system for declaratively creating graphics, based on The Grammar of Graphics". According to its official website: "you provide the data, tell ggplot2 how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details."
- Bokeh: is "an interactive visualization library for modern web browsers".
- Pandas: this library has many tools for data visualization.
If you want to learn data analysis and visualization using Python, Jupyter Notebooks, Numpy, Pandas, CSV files, data frames, and more, you can start your journey with freeCodeCamp's free Data Analysis with Python Certification:
During the certification, you work on and complete these projects:
- Mean-Variance-Standard Deviation Calculator.
- Demographic Data Analyzer.
- Medical Data Visualizer.
- Page View Time Series Visualizer.
- Sea Level Predictor.
freeCodeCamp's YouTube channel also has these great free tutorials to get you started:
- Data Analysis with Python – Full Course for Beginners (Numpy, Pandas, Matplotlib, Seaborn) by Santiago Basulto.
- Python for Data Science – Learn Pandas, Matplotlib, Numpy, and More by DataPublishing
- Matplotlib Crash Course by Keith Galli
- Python NumPy Tutorial for Beginners by Keith Galli
In addition, these are helpful resources if you want to learn how to work with these libraries:
- Matplolib Tutorials: free introductory, intermediate, and advanced tutorials to teach you how to create awesome visualizations.
- Pandas "Getting Started" section: free introductory tutorials.
- NumPy Learn section: a curated collection of external resources to help you get started.
🔸 Machine Learning
Python is an essential tool for every developer who wants to enter the fascinating area of Machine Learning. Let's see a brief introduction to Machine Learning.
What is Machine Learning?
Machine Learning is an area of Computer Science that creates systems that are able to learn on their own.
This type of system uses algorithms that are continuously improved based on input data that helps the system "learn". It learns how to respond autonomously to new scenarios by generating an appropriate output in new scenarios based on previous knowledge.
One of the most amazing things about these systems is that they are continually refined.
They are not like the programs that we typically write in a Python script where we specify every possible action that the program can take. In Machine Learning, the system is trained to "think" and make decisions based on previous knowledge.
This is why we say that machines "learn" from the data.
💡 Tip: This is an interesting talk by Google: Machine Learning Zero to Hero (Google I/O'19).
Neural Networks: The Building-Blocks of Machine Learning
Neural networks are the processing units of the system. They try to simulate a real network of neurons of the brain. They virtual "neurons" receive input, learn how to process that input, and generate an output based on their previous knowledge.
This is very similar to what out brain does every single moment of every single day.
Thanks to neural networks, a Machine Learning algorithm can learn how to predict the expected output from a given input based on previous knowledge.
For example, when you see recommended videos on YouTube, those recommendations were generated by neural networks that predict what videos you might like to watch based on your previous patterns. Amazing, right?
💡 Tip: This is an interesting article by Google if you would like to read more about this YouTube example.
Python and Machine Learning
I'm sure you must be asking: what is the role of Python in this area? It is one of the most popular and powerful tools used to program this type of system.
One of the most popular libraries used by developers around the world to work with Python applied to Machine Learning is TensorFlow. It's a free open-source library developed by the Google Brain Team. This library is used for research and production at Google.
According to Jeff Dean, the lead of Google's Artificial Intelligence division:
Today it is used heavily in our speech recognition systems, in a new Google Photos product, Gmail, and Google Search. (source)
The best part is that developers all over the world can use this library to tackle real-world problems.
💡 Tip: This is a great video about TensorFlow made by Google.
These are two other popular Python libraries used for Machine Learning:
- Keras – an open-source neural-network library written in Python.
- PyTorch – an open-source Machine Learning library used for developing and training neural networks.
Machine Learning Projects in Python
The potential of Machine Learning is really endless. It can be applied to virtually any area and context that you can think of. If the task requires learning from patterns and predicting output, then a Machine Learning model can definitely help.
For example, to give you an idea of the type of projects that you can create, freeCodeCamp's curriculum includes a free Machine Learning with Python Certification:
During the certification, you work on and complete these projects:
- Rock Paper Scissors.
- Cat and Dog Image Classifier.
- Book recommendation engine using K-Nearest Neighbors.
- Linear Regression health costs calculator.
- Neural Network SMS classifier.
More Examples of Real-World Applications
You can find more examples of the applications of Machine Learning in Kaggle, an "online community of data scientists and machine learning practitioners" owned by Google.
In this platform, you can practice your Python and Machine Learning skills by working on projects and participating in competitions.
To give you an idea of the type of projects that you can tackle with Machine Learning, previous competitions in Kaggle include:
- Predicting lung function decline.
- Predicting survival on the Titanic.
- Building tools for bird population monitoring.
- Labeling famous landmarks.
- Forecasting COVID-19 spread.
- Estimating the unit sales of Walmart retail goods.
- Identifying videos with face or sound manipulations.
- Predicting wait times at major city intersections.
- Detecting fraud from customer transactions.
- Predicting a movie's worldwide box office revenue.
- Predicting pet adoption.
- Identifying risk when pilots are distracted, sleepy, or in other dangerous cognitive states.
As you can see, just in this short list of projects, the applications range from medicine to business, from biology to risk detection, and from fraud detection to image processing. The possibilities are truly endless when you tackle real-world problems using Machine Learning.
freeCodeCamp's YouTube channel has these helpful tutorials to get you started with Machine Learning in Python:
- TensorFlow 2.0 Complete Course - Python Neural Networks for Beginners Tutorial
- Develop an AI to play Connect Four - Python Tutorial
- Scikit-Learn Course - Machine Learning in Python Tutorial
- PyTorch for Deep Learning - Full Course / Tutorial
🔹 Web Development
Python is used in the field of web development to build the back-end of web applications. Let's start this section by talking a little bit about what the back-end is and how it helps us to create web applications.
Python for Back-End Web Development
In a web application, all the code used to interact with the user and create what the user sees is called the front-end part of the application.
Python is used to code the behind-the-scenes functionality of the application, the part that powers all the functionality of the application but that you don't see directly on screen.
It handles the server-side of the application, interacting with all the necessary databases when the user requests data. It returns the requested data to the user to make the application run as expected.
💡 Tip: Full-Stack Web Development involves both the front-end and back-end of a web application to make it presentable to the user while working with databases.
These are some popular Python web frameworks:
- Django: a "high-level Python Web framework that encourages rapid development and clean, pragmatic design."
- Flask: a very popular microframework used to develop web applications in Python.
- Pyramid: a "small, fast, down-to-earth Python web framework."
- Web2Py: a "free open source full-stack framework for rapid development of fast, scalable, secure and portable database-driven web-based applications."
- Bottle: a "fast, simple and lightweight WSGI micro web-framework for Python."
freeCodeCamp's YouTube channel has great free tutorials to learn web development in Python:
- Python Django Web Framework - Full Course for Beginners
- Learn Flask for Python - Full Tutorial
- Web Programming with Flask - Intro to Computer Science - Harvard's CS50 (2018)
- Full stack Python Flask tutorial - Build a social network
These are also great free resources to learn how to work with these frameworks:
🔸 Computer Science Education
Python currently plays a key role in computer science education around the world. Let's see why.
Python is so widely used as a teaching tool because:
- It is easy to learn: its syntax is simple and it can be learned quickly. Students start diving into more advanced aspects of computer science much more quickly than with other programming languages.
- It is powerful: it is used in real-world applications, so students immediately start acquiring valuable skills for their careers.
- It is versatile: it supports various programming paradigms including imperative programming, functional programming, procedural programming, and object-oriented programming.
The creator of the Python language, Guido van Rossum, stated that:
Now, it's my belief that Python is a lot easier than to teach to students programming and teach them C or C++ or Java at the same time because all the details of the languages are so much harder.
Python's syntax is simple and straightforward, so students can start learning computational thinking and problem-solving skills much more quickly, which is usually the main goal of introductory computer science courses.
Python in the Classroom and Online Learning
Many universities and schools around the world have decided to teach introductory programming and computer science courses using Python.
For example, MIT, one of the world's leading universities in the field of technology, teaches introductory computer science and programming using Python (both in the on-campus and online versions of the course on edX).
According to an article by MIT News published when the online version of the course reached 1.2 million enrollments, the course "has become the most popular MOOC in MIT history".
This clearly shows that Python's popularity continues to rise. In the article you can find testimonies of students who learned Python and how this new knowledge improved their lives.
In the article, Professor Ana Bell, lecturer in the EECS Department at MIT, states that:
“At its core, the 6.00 series teaches computational thinking...It does this using the Python programming language, but the course also teaches programming concepts that can be applied in any other programming language.”
This clearly shows the potential of Python as a teaching tool. It can be used to teach higher level concepts that can be applied to other programming languages.
And it does this without the extra layer of complexity that the syntax of other programming languages like Java or C might add to the learning process.
During the last few years, online courses have become an important part of the daily lives of learners of all ages worldwide. The variety of free online courses and resources has expanded tremendously in the last few years.
For example, freeCodeCamp's curriculum includes three free certificates with projects to help you expand your Python skills in key areas with high demand worldwide:
- Scientific Computing with Python.
- Data Analysis with Python.
- Machine Learning with Python.
Harvard University also offers these online courses that can be audited for free:
- CS50's Introduction to Computer Science.
- CS50's Introduction to Artificial Intelligence with Python.
Python has definitely become a key tool that has improved computer science education worldwide. And it will continue to do so in the future.
If you are thinking about teaching a course using Python or learning Python, I guarantee you that your time and effort will be totally worth it.
🔹 Computer Vision and Image Processing
Python is used for computer vision and image processing, fields that are expanding rapidly.
The goal of image processing is to process an image, apply transformations to it, and return a new version of the original image.
In contrast, the goal of computer vision is more complex because it tries to make the computer understand and interpret an image and its content.
Let's start with image processing. With a Python library, you can perform operations such as:
- Cropping, flipping, and rotating.
- Manipulating exposure and color channels.
- Detecting edges and lines.
- Adding filters and restoring images.
Now let's dive into computer vision. If you start researching this topic, you might be surprised by its current applications. Some of them are:
- Object and Event Detection.
- Facial recognition.
- Image classification.
This scientific field is so important that Google developed a tool called Cloud Vision, which has a Python version for developers to incorporate this functionality into their programs.
According to the "Using the Vision API with Python" tutorial in Google Codelabs, the Google Cloud Vision API:
Allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content.
This set of tools provides functionality for face detection, landmark detection, logo detection, label detection, text detection, and more.
💡 Tip: One of the most amazing applications of computer vision is the development of software to control self-driving cars. These vehicles need to "see" where they are driving, where the lane is, and what objects surround them (including other vehicles). Computer vision plays a key role in this functionality.
These are some awesome libraries for computer vision and image processing:
- OpenCV: an "open source computer vision and machine learning software library". Its Python version is called OpenCV-Python.
- scikit-image: a "collection of algorithms used for image processing".
- NumPy: it can be used to process the pixels of an image as a 2D array.
- SciPy: the scipy.ndimage package "contains various functions for multidimensional image processing."
🔸 Game Development
Games definitely shape lives and create timeless memories. They will continue to be part of our society in the years to come. Python is already there, lighting the spark of game creation.
Python Game Development Frameworks
According to the official Python Documentation, there are two main Python frameworks used to develop games:
- pygame: "the original and still very much active package for game development using Python. It allows Python to talk to SDL, a cross-platform, multimedia library. Because it needs to be compiled for each platform and each Python version, there can be a lag when a new Python version comes along."
- pyglet: this is "the newcomer, based on OpenGL. Because it is a pure Python package, it can be used as is even when a new Python version is released (except for the Python 2 to Python 3 transition)."
You can also use the turtle module to create simple games. Turtle is a built-in Python module that is installed automatically when you install Python in your computer. It helps you to create games with simple graphics and with a simple user interface.
If you want learn game development in Python, freeCodeCamp's YouTube channel has these great free tutorials:
- Learn Python by Building Five Games - Full Course
- Python and Pygame Tutorial - Build Tetris! Full GameDev Course
- Snake Game Python Tutorial
🔹 Medicine and Pharmacology
Python also has amazing applications in the medical field. You will be surprised by how technology is being combined with medical knowledge to provide accurate and efficient diagnoses and treatments to patients.
Some examples of the use of Python in medicine and pharmacology include:
- Making clinical diagnoses based on the patients' medical records and symptoms.
- Analyzing medical data.
- Making computational models to speed up the process of development of new medications.
These broad applications include thousands and thousands of examples around the world. I selected a few of them to illustrate how Python is shaping this field. Let's take a look at them.
Pharmaceutical Success Story: AstraZeneca
According to the official Python Documentation, one of the world's leading pharmaceutical companies, AstraZeneca, used Python to improve their existing computational models to make them "more robust, extensible, and maintainable".
Researchers used these models simulate the chemical structure of molecules and their effect in the body. This helped scientists identify potential molecules for new drugs and start testing them more quickly in the laboratory.
When he joined the team, Andrew Dalke, being a a "well-known advocate for Python in computational chemistry and biology" convinced the team that Python was exactly what they needed.
Python was chosen for this work because it is one of the best languages available for physical scientists, that is, for people who do not have a computer science background.
He stated that:
Python was designed to solve real-world problems faced by an expert programmer. The result is a language that scales well from small scripts written by a chemist to large packages written by a software developer.
Amazing, right? Python can power the computational models that pharmaceutical laboratories use to develop new drugs.
Red Blood Cells (RBC) Identification
Another interesting medical application of Python is related to Hematology. Usually, specialized professionals analyze blood tests by counting and identifying cells manually, but this can be improved with the help of automation.
Researchers found that Python can be the right tool for the job. Let's see an interesting project.
The goal of this project is to identify and classify red blood cells shapes based on images taken from optical microscopes. According to this article, "RBC shape can help to diagnose diseases and disorders such as leukaemia, sickle cell anaemia and malaria."
The project was developed by researchers from the Bioresource Processing Research Institute Australia. It was programmed in Python and it used image processing Python packages and libraries such as numpy, scipy, opencv-python, scikit-learn, and matplotlib.
Python Medical Packages
- pyGeno: an open-source Python package developed by Tariq Daouda at the Institute for Research in Immunology and Cancer (IRIC). It's intended for "precision medicine applications that revolve around genomics and proteomics". It works with reference and personalized genomes.
- MedPy: an open-source Python library "for medical image processing in Python, providing basic functionalities for reading, writing and manipulating large images of arbitrary dimensionality."
Real-World Medical Applications (Examples)
- Gusztav Belteki presented another example during his talk at PyData Berlin 2018 "Python in Medicine: analysing data from mechanical ventilators." The goal of his research was to "interpret large datasets retrieved from modern equipment used in neonatal intensive care, mechanical ventilators and patient monitors."
- At PyCon 2019, Jill Cates gave this presentation titled "How to Build a Clinical Diagnostic Model in Python."
🔸 Biology and Bioinformatics
Python also has amazing applications in the world of Biology and Bioinformatics. These include processing DNA sequences, simulating population dynamics and genetics, and modeling biochemical structures.
Biopython is a Python framework with "freely available tools for biological computation". Its goal is to "address the needs of current and future work in bioinformatics."
According to its documentation, this framework includes functionality such as the ability to:
- Work with sequences and perform common operations on them such as transcription, translation, and weight calculations.
- Connect with biological databases.
- Perform classification of data using K-Nearest Neighbors, Naive Bayes, and Support Vector Machines.
- Work with phylogenetic trees and population genetics.
The documentation states that "the goal of Biopython is to make it as easy as possible to use Python for bioinformatics by creating high-quality, reusable modules and classes."
Rosalind: Practice Python by Solving Bioinformatics Challenges
Rosalind is "a platform for learning bioinformatics through problem solving." It is "free and open to the public" (the FAQ page indicates that it is in beta mode).
Python can be used to solve the challenges on the platform. Since this is a very popular programming language in the platform, there is a "Python Village" section where you can learn the basics of Python before tackling bioinformatics algorithms.
Users solve the problems by running their solutions on their computer, processing the given dataset, and copy/pasting the output to check the answer.
💡 Tip: The project's name commemorates Rosalind Franklin, "whose X-ray crystallography with Raymond Gosling facilitated the discovery of the DNA double helix by Watson and Crick".
Packages and Frameworks
- ProDy: a free and open-source package "for protein structural dynamics analysis" developed by Bahar Lab at the University of Pittsburgh.
- PySB: a "framework for building mathematical models of biochemical systems as Python programs" developed by members of the Lopez Lab at Vanderbilt University and the Sorger Lab at Harvard Medical School.
- The Community Simulator: this is a "freely available Python package for simulating microbial population dynamics in a reproducible, transparent and scalable way" developed by researchers at Boston University.
💡 Tip: If you would like to learn more about the applications of Python in Bioinformatics, here's a talk by Martin Schweitzer at PyCon Australia: "Python for Bioinformatics for learning Python".
🔹 Neuroscience and Psychology
Python also has applications in neuroscience and experimental psychology research.
Python in Neuroscience
According to the article Python in neuroscience written by researchers from the Center for Brain Simulation, Ecole Polytechnique Fédérale de Lausanne, Geneva, Switzerland:
Computation is becoming essential across all sciences, for data acquisition and analysis, automation, and hypothesis testing via modeling and simulation.
In regards to Python, they state that:
It became clear to us in 2007 that we were on the cusp of an emerging Python in neuroscience ecosystem, particularly in computational neuroscience and neuroimaging, but also in electrophysiological data analysis and in psychophysics.
As you can see, Python and computation have been expanding across all sciences.
It is used by many labs worldwide for psychophysics, cognitive neuroscience and experimental psychology.
The official website of this package states that it is:
- Easy for learning.
- Precise enough for Psychophysics.
- Online or lab-based depending on the user's choice.
Python also has applications in Astronomy and Astrophysics. Let's see three of the main Python packages used in this scientific area:
The Astropy package "contains various classes, utilities, and a packaging framework intended to provide commonly-used astronomy tools."
Astropy is part of a larger project called The Astropy Project, which is "is a community effort to develop a common core package for Astronomy in Python and foster an ecosystem of interoperable astronomy packages."
According to its About page, one of its goals is to "improve usability, interoperability, and collaboration between astronomy Python packages."
💡 Tip: You can see examples of projects made with Astropy in the Example Gallery.
The SunPy package is described as "the community-developed, free and open-source solar data analysis environment for Python." It builds upon the capabilities of Python packages such as NumPy, SciPy, Matplotlib, and Pandas.
The SpacePy package is "a package for Python, targeted at the space sciences, that aims to make basic data analysis, modeling and visualization easier."
According to its official Documentation:
The SpacePy project seeks to promote accurate and open research standards by providing an open environment for code development.
According to the description of its GitHub repository, it has superposed epoch classes, drift shell tracing, access to magnetic field models, streamline tracing, bootstrap confidence limits, time and coordinate conversions, and more.
🔹 Other Applications
Python can also be applied in many other areas, including:
- Robotics: Python can be used to program robots. A library written for this purpose is pybotics, "an open-source Python toolbox for robot kinematics and calibration".
- Autonomous vehicles: Python can be used to program the software that controls self-driving cars. These cars need computer vision to "see" where they are driving, where the lane is, and what objects surround them.
- Meteorology: The package climate-indices "contains Python implementations of various climate index algorithms which provide a geographical and temporal picture of the severity of precipitation and temperature anomalies useful for climate monitoring and research."
- Business: Python can be a powerful tool to analyze data generated by businesses and to forecast future trends.
- Graphical User Interface (GUI) Development: Python can be used to create graphical user interfaces with tools like tkinter.
- If you're interested in learning more about this, freeCodeCamp has a great tutorial on YouTube: Tkinter Course - Create Graphic User Interfaces in Python Tutorial.
There are many applications of Python in every area that you can possibly imagine. I hope that this article gave you an idea of the wide range of real-world applications of this programming language in industries that are currently shaping our world.
Remember that no matter which field you are in or which field you want to be in, learning Python will definitely open many doors for you. It is here to stay. And it has transformed and improved our current world and it will continue to do so for many years.