Well, I meant to say things like:
- How do statements end (semicolon or no semicolon)
- How to write if's, for's and while's
- Operators
- Class and function definition
These are some differences between Python and C++
Python:
#Statements need no semicolon
print("Hello world!") #Function call. Arguments go inside parentheses. Strings go between quotes.
x = 0 # Assignment operator
#Structure of an IF
if x == 0: # Comparison operators
print("True") # Forced indentation for scope, no brackets.
else: # Colon after if, elif, else
print("False")
list = [1,2,3,4]
# Structure of a for loop
for item in list:
print(item)
# Structure of a while loop
while list[0] != 1:
print("Looping...")
# Function definition
def foo(arg1, arg2): #keyword def, arguments between parentheses, colon
-- code to run -- # Forced indentation
# Class definition
class Foo:
def __init__(self):
-- contructor code --
-- define more attributes methods --
C++
// Needs main function
#include <iostream>
using namespace std; // Statements need semicolons
int main()
{
cout << "Hello World!" << endl; // Bitwise shift operator
return 0; // Indentation is optional, brackets are necessary to indicate scope
}
int x = 0; // Assignment operator (strong-typed language, not syntax related, though)
// Structure of an IF
if (x == 0)
{
cout << "True" << endl;
}
else
{
cout << "False" << endl;
}
// For loop
for (int i = 0; i < 10; i++)
{
// some code
}
// While loop
while (variable == value)
{
// some code
}
// Function definition
void Foo(int arg1, bool arg2) // starts with type, arguments between parentheses, also with type
{
// some code
}
// Class definition
class Foo
{
int privateAttribute; // Attribute
public:
Foo() // Constructor
{
privateAttribute = 0;
}
}
The examples might not be 100% accurate, but my point is that if you know what you're doing, syntax shouldn't be too much of a problem. How long did it take you to see the differences between the two blocks of code? And notice how syntax is consistent across the language, so the differences between a language and another tend to be consistent also.
A different thing is the actual use and logic of each language which can be extremely different, and it can take weeks or months to make the switch from one language to another.