If you’ve been exploring AI tools like ChatGPT, Claude or Gemini, you’ve probably run into the term Python. So, what exactly is Python, and why is it often linked with AI? Should you learn Python? This article aims to shed light on these questions. We’ll briefly journey through Python as a programming language and then dive into its vital roles in AI.
Because learning Python requires considerable time and effort, especially for those new to programming, I aim to provide insights that help you decide if learning Python is the right thing to do for you.
What is Python
Let’s start by clarifying precisely what Python is. Python is one of the world’s most used and most popular programming languages. It’s powerful, versatile, and easy to learn. Python is widely used in applications like web development, Data Science, Machine learning, and Artificial Intelligence (AI). It’s one of the easier languages to learn, making it ideal for beginners.
Many people say that Python comes with batteries included. In other words, it includes a comprehensive base library. In addition, because so many people use Python, hundreds of thousands of high-quality libraries and frameworks exist to get things done quickly and without hassle. You can do a lot with a little bit of Python code!
How Python is used in AI
But why do we see Python mentioned so often alongside AI topics? It’s because, in some form or another, Python is used a lot in the AI world. These are the three ways Python is used in AI:
- First, AI assistants can write and run Python code for you.
- Secondly, you can use Python to leverage the many AI and machine learning libraries and create cool products.
- And third, you can use Python to call AI models through an API (like the ones from OpenAI and Anthropic), or run models on your own computer, and build on top of them.
1. Generation of Python code by AI’s
AI models are very good at writing Python code. Chat assistants like ChatGPT and Claude can also run the Python they write: ask them to analyze a spreadsheet or draw a chart, and under the hood they write and run Python using well-known libraries like NumPy, pandas, and matplotlib. AI coding assistants go a step further. Tools like GitHub Copilot, Claude Code and OpenAI’s Codex work inside your editor or terminal, and can write, run, and fix entire programs.
That doesn’t make learning Python less useful. You still have to read what the AI wrote, decide if it’s correct, and fix it when it isn’t. When you know Python, you can understand, tweak, and extend generated code. Without that knowledge, you end up doing what is often called voodoo coding: programming without really knowing what you’re doing!
Here’s an example of why. In 2023, I asked ChatGPT to create a small program that translates English to German using the OpenAI API, and it happily complied:

This code looks reasonable, but it doesn’t work today. The OpenAI library has changed, and with a current version, openai.Completion fails with an APIRemovedInV1 error. AI models learn from code that was written in the past, so they sometimes suggest outdated solutions. If you know Python, you’ll spot and fix problems like this quickly.
2. Using other libraries
Python is the most widely used programming language in the AI and machine learning landscape due to the availability of powerful AI and machine learning libraries. By this, I don’t mean APIs (see the next section) but libraries you can download and run on your PC. I’ll briefly list the most well-known and most used ones; perhaps you’ve heard of some of them.
TensorFlow
Developed by the Google Brain team, TensorFlow is an open-source library that is highly popular for creating deep learning models. Its flexible architecture allows easy computation across multiple platforms and comes with a wealth of resources for learning and development.
PyTorch
Originally created by Facebook’s (now Meta) artificial intelligence research group, PyTorch is a Python-based scientific computing package. It stands out for its dynamic computational graph, which makes it a favorite for research and for projects that require complex, custom AI models. Most of today’s open AI models are built and trained with PyTorch.
SciKit-Learn
A go-to library for beginners in machine learning, SciKit-Learn provides simple and efficient tools for data analysis and modeling. It’s particularly praised for its clear documentation and user-friendly design.
Keras
As a high-level neural networks API, Keras is popular for its user-friendly and modular nature. Since Keras 3, it runs on top of JAX, TensorFlow, or PyTorch, so you can write your model once and pick the engine that runs it.
Hugging Face Transformers
Transformers gives you access to thousands of pre-trained models for text, images, and audio, which you can download from the Hugging Face Hub. With a few lines of Python, you can run a model for translation, summarization, or image recognition on your own computer, or fine-tune it for your own task.
If you’re looking into building your own AI tools, you will need to learn Python to unlock the potential of these and many more libraries that provide us with the foundation to implement complex machine learning models, analyze vast amounts of data, and contribute to the evolution of AI.
3. Calling external APIs
Another crucial application of Python in AI is the calling of external Application Programming Interfaces (APIs). An API is a set of rules that allows one piece of software to interact with another. In the context of AI and machine learning, APIs can be used to access pre-trained models or other AI services on the web. For example, OpenAI provides an API for its GPT models, and Anthropic provides one for its Claude models. Both offer an official Python library (openai and anthropic) that lets you send a prompt to a model and get the answer back in a few lines of code. In the screenshot I shared above, we actually asked ChatGPT to use the OpenAI API.
This is how most AI-powered apps are built today: a regular Python program that sends text, images, or files to a model and does something useful with the answer. You don’t need to know how to train a model to build one.
Side note: if you want to experiment without paying for an API, you can run open models on your own computer. Ollama makes that easy, and llama.cpp is a popular engine to run them. Both offer a local web server with an API that’s compatible with the one from OpenAI, so the same Python code works with either. Local models are less powerful than the big ones, though, and how fast they run depends on your hardware.
Should I learn Python?
So… should you learn Python? If you ask me, the answer is a resounding Yes! I think you should, no matter what. By learning Python, you’ll be better equipped to understand and use the generated code by an AI. And perhaps, later, you’ll even be able to use APIs or the machine learning and AI libraries I mentioned to create your own AI-based products.
And even if you give up on it at some point, you’ll still have learned a great deal. Learning to program a computer will greatly enhance your understanding of how computers and the software you use daily work and will surely give you an advantage in life.
How to learn Python?
Start with our free Python tutorial to learn the fundamentals, from your first program onward.
Prefer to learn by doing? The interactive courses on learn.python.land let you write and run Python right in your browser.