Tuesday, November 29, 2016

Transition from C/C++/Java to Python

I am trying to learn Python myself, as it greatly expedites prototype development compared to C/C++/Java.
Here is quick conversion of C/C++/Java common codes into Python:

for (int i=0; i<N; i++) {
for i in range(N):

if (x==y) {

if x==y:

!true

not True

else if {

elif:

printf("%d\n", i)

print i

printf("%d ", i)

print i,

for (int i : array) {

for i in array:

vector<int> v;

v.push_back(1);
v.push_back(2);
v = [1,2]

// C++
vector<int> u,v;
...
v = u;
import copy
v = copy.copy(u) // OR // v = u[:]

// C++ vector<int> &u, &v;
...
v = u;
v = u

No comments:

Post a Comment