Here is a comparison of basic programming rules in C++ and Python, along with simple code examples to illustrate each concept:
🔹 1. Program Structure and Syntax
| Concept | C++ | Python |
|---|---|---|
| File extension | .cpp | .py |
| Compilation | Required (e.g., g++) | Interpreted |
| Semicolons | Required (;) | Not used |
Braces {} | Used to define blocks | Indentation defines blocks |
Example: Hello World
C++
Python
🔹 2. Variables and Data Types
| C++ | Python |
|---|---|
| Variables must be declared with a type | Dynamically typed |
int, float, char, etc. | int, float, str, etc. |
C++
Python
🔹 3. Input/Output
| C++ | Python |
|---|---|
Uses cin and cout | Uses input() and print() |
C++
Python
🔹 4. Conditional Statements
C++
Python
🔹 5. Loops
For loop
C++
Python
While loop
C++
Python
🔹 6. Functions
C++
Python
🔹 7. Classes and Objects
C++
Python
No comments:
Post a Comment