A quick reference showing how common Python type hints or decorators translate into C++ using the Py2Cpp compiler.
Python
x = 5
y = 10
z = x + y
print(x+y)C++
#include <iostream>
int main() {
long x = 5;
long y = 10;
long z = x + y;
std::cout << (x + y) << std::endl;
return 0;
}Basic variable declaration and arithmetic
Python
def add(a: int, b: int) -> int:
return a + b
result = add(3, 4)
print(result)C++
#include <iostream>
long add(long a, long b) {
return a + b;
}
int main() {
long result = add(3, 4);
std::cout << result << std::endl;
return 0;
}Defining and calling a function with type hints