101

What is the base language Python is written in?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Dewsworld
  • 13,367
  • 23
  • 68
  • 104

6 Answers6

142

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)
Chaitanya Bapat
  • 3,381
  • 6
  • 34
  • 59
Roman Bodnarchuk
  • 29,461
  • 12
  • 59
  • 75
46

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

wRAR
  • 25,009
  • 4
  • 84
  • 97
17

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

Gandaro
  • 3,427
  • 1
  • 17
  • 19
  • 2
    Actually PyPy is written in RPython – Jakob Bowyer Feb 26 '12 at 11:26
  • @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). – Duncan Feb 26 '12 at 13:00
9

it is written in C, its also called CPython.

neizod
  • 1,582
  • 15
  • 24
5

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

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

nealmcb
  • 12,479
  • 7
  • 66
  • 91
  • 1
    do you mean "surprisingly not" or "not surprisingly"? – necromancer Jan 17 '18 at 09:46
  • @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. – nealmcb Jan 21 '18 at 15:06
  • 1
    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. – necromancer Jan 21 '18 at 23:15
  • "*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 Aug 09 '22 at 14:30
  • 1
    @TylerH Thanks - it did deserve some clarification and a reference.... – nealmcb Aug 17 '22 at 01:07