Some hints on what is different when programming Python if you are coming from C-based languages or Visual Basic, like used in Mach3.
Indentation
Indentation is mandatory for loops and conditions. Accepted are either four white spaces or a tab.
Case sensitivity
Pyton is picky, be careful with keywords and variable names as they are case sensitive.
Py – ERROR
setSomething(True)
#does not work!
Py – OK
setSomething(true);
#works fine
Semicolon
At least one thing where we can stick to old habits, for C-developers at least. Semicolons at line end are supported but not mandatory in Python.
C
DoSomeThing();
Py
DoSomeThing(); # also fine!
DoSomeThing()
If, then, else
If you come from C, you will really miss the curly brackets as well as the semi-colons after each line… At least for me, this was one of the most confusing things in the beginning.
VB
if var == 1 then
doSometing()
Else
doSomethingElse()
EndIf
C
if(var == 1){
doSomething();
}Else{
doSomethingElse();
}
Py
if var == 1:
doSomething()
Else:
doSomethingElse()
Commenting
Similar to C, but different to VB
VB
DoSomeThing() 'Comment
' Multi
' line
' comment
C
DoSomeThing(); // Comment
/*
Multi-line
comment
*/
Py
DoSomeThing() # Comment
"""
Multi-line
comment
"""