Why is Python primarily used in artificial intelligence?

I haven’t surveyed others in the field for their reasons, but I will provide mine. You’ll need to aggregate the results from others to gain an understanding of “why” Python is primarily used in AI. Chances are, though, that some of the reasons overlap.

My background is in physics, not programming. Software development wasn’t my career choice. As I developed my ideas for machine intelligence, I needed to experiment with them to rapidly prove them out or trash them for better ideas. So, I surveyed a bunch of programming languages. At the time, Python was not as popular as some other languages, but had a good community around it. Critical for my purposes, it:

  1. Was easy to learn. I didn’t have to change the way I think to encode a problem and solution. Curly braces and static typing didn’t get in my way. My goal was to create and prove theories, not to develop software. Also part of this point was the previously mentioned good community around it. It was often easy to find help towards a solution of a specific coding challenge.
  2. Allowed me to iterate through solutions rapidly. Since there’s no need to compile solutions, I was able to make and test incremental changes very quickly.
  3. Has excellent libraries for scientific computing, even back then. AI is not a programming problem. It is a science and engineering problem. Having those tools available as modules rather than building them from scratch helped with point #2.

One complaint that I would hear all the time back then was that Python is too slow. (Maybe the complaints are still vocalized, but I have long since ignored this as a non-issue.) What is more important in my research work is that the solutions are correct. Speed is not a concern. Getting to a wrong solution faster than anyone else isn’t an advantage, unless that allows you to iterate your solutions quicker (see #2 above). So, although Python programs may run slower than, say Java, most of the speed gained is during development time. Besides, Moore’s Law allows me to sit on my solution for 2 years and it will run twice as fast. ;-)

It is likely that others working in the field have also come to use Python for similar reasons. It should be noted that Python evolved from another programming language that was popular among the AI practitioners of its time, Lisp. One of AI’s greats, Peter Norvig, who co-authored the textbook on modern AI[1]along with another great, Stuart Russell, describes Python as “a dialect of Lisp with "traditional" syntax”[2]

In my belief, Norvig and Russell’s textbook helped make Python popular among AI practitioners and researchers alike due to the large amount of examples provided in Python code[3]. The historic pedigree with Lisp may have also contributed. So, these final two factors may have also contributed to Python’s popularity in AI.