106

What is the base language Python is written in?

2

6 Answers 6

145

You can't say that Python is written in some programming language, since Python as a language is just a set of rules (like syntax rules, or descriptions of standard functionality). So we might say, that it is written in English :). However, mentioned rules can be implemented in some programming language. Hence, if you send a string like 'import this' to that program called interpreter, it'd return you "Zen of Python".

Since most modern OS are written in C, compilers/interpreters for modern high-level languages are also written in C. Python is not an exception - its most popular/"traditional" implementation is called CPython and is written in C.

There are other implementations:

  • IronPython (Python running on .NET)
  • Jython (Python running on the Java Virtual Machine)
  • PyPy (A fast python implementation with a JIT compiler)
  • Stackless Python (Branch of CPython supporting microthreads)
Sign up to request clarification or add additional context in comments.

3 Comments

Note that PyPy is written in RPython.
"You can't say that Python is written in some programming language" You of course can say this, because CPython is the reference implementation and it's written in C, so Python is written in C.
49

The sources are public. Python is written in C (actually the default implementation is called CPython).

3 Comments

I came here wondering which C it's written in (C99 or something else).
@Boris C99 according to configure.ac
The default implementation is called CPython, but only since some time (IIRC) after another implementation came into existence (Jython).
17

Python is written in English. But there are several implementations:

2 Comments

Actually PyPy is written in RPython
@JakobBowyer You can execute PyPy using CPython so it is perfectly true to say it is written in Python. The fact that for performance reasons it uses only a subset of Python is more of an implementation detail (but a very interesting and mind twisting detail).
9

it is written in C, its also called CPython.

Comments

5

You get a good idea if you compile python from source. Usually it's gcc that compiles the *.c files

Comments

1

To add to and reframe some of the other good answers:

The specification for Python (question) is written in English, but could be written in a formal semantics, as Standard ML and Scheme are. See Programming language specification.

There are implementations of Python in many languages, as noted in Gandaro's answer.

Updated thanks to the inspiration of @TylerH:

As an aside, when the performance of a compute-intensive application is important, the fastest implementation is often not the standard CPython, which is written in C. For example, for many cases, pypy or Cython (both written in Python) may be faster

5 Comments

do you mean "surprisingly not" or "not surprisingly"?
@necromancer I mean the former, i.e. that I am surprised that the fastest implementation is not the reference implementation in C. But I suppose it isn't surprising that there are folks out there that can improve on performance, since they won't necessarily have to deal with other constraints that the reference implementation wants to fulfill.
I'd think the language of the implementation would be less relevant than (a) the sophistication of a dynamic compiler that converts python source into machine code. This compiler could be in any language; what matters is the quality of algorithms; (b) the machine code of certain libraries. Python is famous for numerical libraries that are not written in Python but merely "glued" into the environment; and (c) the benchmark; certain programs may run faster in one implementation than others.
"of which the fastest is surprisingly not the original CPython, which is written in C." Citation needed. Also I concur that the wording of this quoted section is pretty awkward.
@TylerH Thanks - it did deserve some clarification and a reference....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.