2020/07/04

Compare the if condition between Matlab and Python

When coding with multiple programming languages, sometimes it is confusing to choose the right syntax for each language. Here is an example for the if condition in Matlab and Python:

Matlab

a = 1;
b = 2;

if a == 1
   disp('Hello');
else
   disp('Hi');
end
if b ~= 1
   disp('World'); 
end

Result:

Hello
World
>> 

Python

a = 1
b = 2

if a == 1:
   print('Hello')
else:
   print('Hi')

if b != 1:
   print('World')

Result:

Hello
World