您的位置:首页 > 编程语言 > C语言/C++

What's the difference between C++ and Python

2015-07-20 11:07 197 查看
In Principle

1. C++ is a "statically typed" language, while Python is a "dynamically typed" language.

In one case, the types of the main components of the set of instructions (the computer program) are explicitly declared while in the other case they aren't.

In Practice

2. C++ is "faster" than Python. C++ is typically a "compiled" language while Python is typically an "interpreted" language.

With C++, the instructions are very well understood with all types specified and so they are translated into machine code (they are compiled) and executed unambiguously by the computer ...while with Python a separate computer program has to figure out
what the Python instructions really mean [2,3] and how to "interpret" them to produce an output. The overhead of running this extra program versus simply just running the well defined machine code typically ensures that C++ runs much faster than Python.

3) Python is more concise than C++

Python is considered to be cleaner and more direct, with emphasis code readability.

Though this is certainly not an absolute truth, the example also shows one of the reasons why Python code tends to be shorter than that written in C++ (i.e. there is no need to declare types explicitly and this literally saves space in written code). Smaller
code size for the same task leads to "rapid prototyping" and this is partly why one would use something like Python when speed of development is important.

4) Python has garbage collection while C++ not.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: