Set Script Home as “Starred⭐” to receive article updates immediately
Recently, I came across an interesting question: Why is Python slow in execution, yet it is used for AI?
Many people criticize Python for being an interpreted language, inherently slow compared to compiled languages like C++ and Java, which are more stable and faster. So why is Python widely used in the development of large AI models? In fact, all LLM-related repositories on GitHub primarily use Python.
This requires analysis from two perspectives. First, the core tasks of AI projects involve data processing, algorithm validation, and parameter tuning, where the demands for speed and stability are not as stringent. Secondly, Python is not as weak as you might think. Remember, any product or technology recognized by the market has its irreplaceable value.

It is true that Python is inherently slow, but it is a glue language that allows you to write low-level algorithms in other languages and then wrap them into third-party libraries using Python, achieving high efficiency. For example, NumPy is written in C, yet it is the most user-friendly and fastest matrix computation library, widely used in AI computations. Many libraries like pandas, scipy, and sklearn are built on top of NumPy.
Moreover, the most popular deep learning frameworks in Python, TensorFlow and PyTorch, are written in C++. Python provides the API interface and integrates with other Python libraries.
You might know about something called Cython, which can compile Python code to C/C++, and then to machine code, allowing you to enjoy the performance and speed of C/C++ while writing with the efficiency of Python.
Python is like a universal key, capable of doing things it is not particularly good at, because it is compatible with various technology stacks and programming languages. For instance, it excels in data science, leading to a plethora of excellent data processing packages. While it is not suited for writing large software, there are frameworks like PyQt for porting. It may not excel in GPU computing, but CUDA directly provides cuPython, showcasing Python’s compatibility.
Another reason Python is widely used in AI is its simplicity. It allows for the one-click import of thousands of third-party libraries, and its functions and methods are very concise, enabling the fastest implementation of MVPs. This is a crucial trait needed in AI development today: rapid deployment and quick iteration.
For example, to set up an e-commerce customer service agent, you only need to integrate the DeepSeek API using Python, train some local knowledge bases, and simply build a chat interface with FastAPI, all of which can be completed in a day.
from fastapi import FastAPI
import requests
app = FastAPI()
DEEPSEEK_API_KEY = "your-deepseek-api-key"
KNOWLEDGE_BASE = {"Return Policy": "7-day no-reason return", "Shipping Time": "Shipped within 24 hours"}
@app.post("/chat")
def chat(message: str):
if message in KNOWLEDGE_BASE:
return {"response": KNOWLEDGE_BASE[message]}
headers = {"Authorization": f"Bearer {DEEPSEEK_API_KEY}"}
data = {"model": "deepseek-chat", "messages": [{"role": "user", "content": message}]}
return {"response": requests.post("https://api.deepseek.com/v1/chat/completions", json=data, headers=headers).json()["choices"][0]["message"]["content"]}
In summary, the speed required by AI is not only about execution performance but also about the speed of product development, and Python meets both needs very well.
END
Recommended Reading:
- Python developers are switching to Rust! Is it because Claude Code excels in statically typed languages? Rust veterans argue: AI-written Rust code is surprisingly poor!
- The father of Python almost removed import! He believes the module system is the biggest flaw?!
- Programming language rankings for August 2025 | Python is skyrocketing with the support of AI programming assistants!
-
Why has Python become the primary language for artificial intelligence?
-
Git was never meant for version control!
Recommended Reading:
Why has Python become the primary language for artificial intelligence?
Git was never meant for version control!