4

Since Python was written in the C programming language, does it mean that if I know C I will learn and master Python faster than it would take me to learn it without prior knowledge of C?

Or will Python coders find it easier to learn C than programmers from other languages not related to C?

1
  • 12
    Learning Russian will allow you to learn German faster because you have more experience adapting to new foreign languages, but it would make no sense to learn Russian as a warmup if you really just want German. – Brian Gordon Nov 2 '11 at 3:32
17

The reference implementation of Python, CPython was indeed written in C, but saying that Python is written in C is an oversimplification:

  • There are implementations written in other languages, like Jython (written in Java), IronPython (written in C#), PyPy (writen in Python), CLPython (written in Common Lisp), Psyco (also written in C), Stackless Python (written in C and Python) and Unladen Swallow (written in C++)
  • Although the CPython interpreter is written in C, it is possible to write modules for it in C++ or Cython (not to be confused with CPython), as well as C
  • What language a language's interpreter is written in is only important if you want to write modules / extensions to the interpreter itself, it has nothing to do with the language

Several languages (like Java, PHP, C# and others) are referred to as belonging to the C family, that has nothing to do with what language tools (compilers, interpreters) for said languages are written in but it means that they have very similar syntax to C. Python's syntax is very different from C, not only does it not belong to the C family, its actually quite far from it.

Apart from the CPython interpreter, the only other relation that Python has to C is that they are both multi-purpose, multi-paradigm programming languages.

Whichever one you choose to learn first will greatly help you learn the other one, and that's true for every programming language, as the one you learn first will introduce you to programming concepts and ways of thinking that are common in every language.

Python is generally regarded as a higher level language, whereas C as a lower level language, meaning that Python is closer to what we humans consider friendly and C closer to what the machine considers friendly, so Python is a little bit easier for beginners to start with.

1
  • 1
    I just discovered PyPy. Python written in python? :o – apscience Nov 2 '11 at 10:39
12

Python syntax is nothing like that of C. So having prior knowledge of C really has nothing to do with how well you will learn python. Just because under the hood there is C code doesn't mean that you will learn python any quicker because you know C. As a python programmer you are dealing with the syntax of python not C.

1
  • 8
    The syntactic similarities or differences are irrelevant. What matters is the different semantics. – DeadMG Nov 2 '11 at 4:33
2

Languages built on others can operate in fundamentally different ways, introduce new concepts. Just because every operation in Python must be translatable to an operation in C doesn't mean that that operation is feasible or good practice in normal C. The time you expend learning C won't really help you with Python, relatively speaking.

1
  • Python code written like C would be very bad Python. For a beginning programmer, learning C might even slow down the acquisition of Python skill. – Gort the Robot Sep 15 '13 at 2:15
2

Python and C arguably share many concepts, so learning one of these languages will definitely help you with the other one (they belong to the same category of imperative languages, even though they do differ significantly on some points). Here are a few common concepts:

  • "Control structures": loops, tests
  • Function calls and return values
  • Variables have a type (both languages are strongly typed), and operations must respect these types
  • Basic variable types: integers, floats, strings, etc.

That said, Python is both simpler and much more expressive than C: programs written in Python are usually 2-10 times shorter than equivalent C code, and Python offers more useful data structures than C (namely: lists, dictionaries, sets, objects,…).

So, I would strongly recommend that you learn Python first. C will be much easier to learn afterwards, because Python will allow you to grasp the right programming concepts much faster.

Not the answer you're looking for? Browse other questions tagged or ask your own question.