A Brief Comparison of Python and C++ Syntax
These videos on algorithm analysis are well thought out and presented. At issue is that the simple code used for illustration is written in Python, a modern industrial language but not a prerequisite for this course. This page gives code snippets that compare Python with C++. C++ syntax is sufficiently similar to Java that you will readily see the relationship.
The videos on algorithm analysis are well thought out and presented. At issue is that the simple code used for illustration is written in Python, a modern industrial language but not a prerequisite for this course. Shown below are code snippets that compare Python with C++. C++ syntax is suficiently similar to Java that you will readily see the relationship. CS101 is a prerequisit for this course so you are already familiar with C++ and Java.
Where C++ and Java use brackets, {...} to indicate code scope, Python uses indentation. For instance, code indented relative to "for" and "while" statements are within the scope of those statements only. The same is true of the "def" statement used to begin the definition of a function.
Here is function syntax written in Python compared to C++:
PYTHON FUNCTION SYNTAX |
C++ FUNCTION SYNTAX |
|
|
Here is while-loop syntax in Python compare to C++:
PYTHON WHILE-LOOP SYNTAX |
C++ WHILE-LOOP SYNTAX |
|
|
Here is for-loop syntax written in Python compared to C++:
PYTHON FOR-LOOP SYNTAX |
C++ FOR-LOOP SYNTAX |
|
|
Source: Peter Raeth
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.