Matlab requires the end key-word at the end of the block belonging to the for-loop.

Python:

In [1]:

foriinrange(1,11):print(i)

1
2
3
4
5
6
7
8
9
10

Python requires a colon (“:”) at the of the for-line. (This is important and often forgotten when you have programmed in Matlab before.) Python requires the commands to be executed within the for-loop to be indented.

ifa==0disp('a is zero')elseifa<0disp('a is negative')elseifa==42disp('a is 42')elsedisp('a is positive')end

Matlab requires the end key-word at the very end of the block belonging to the for-loop.

Python:

In [2]:

a=-5ifa==0:print('a is zero')elifa<0:print('a is negative')elifa==42:print('a is 42')else:print('a is positive')

a is negative

Python requires a colon (“:”) after every condition (i.e. at the of the lines starting with if, elif, else. Python requires the commands to be executed within each part of the if-then-else statement to be indented.

In Matlab, every object is a matrix. In Python, there is a specialised extension library called numpy (see Sec. [cha:numer-pyth-numpy]) which provides the array object which in turns provides the corresponding functionality. Similar to Matlab, the numpy object is actually based on binary libraries and execution there very fast.