Introduction Python - Basic Syntax
In SimLab, we use Python as one of the two scripting languages for automation.
Print Statement
print("SimLab Automation")
MeshSize = 3
print("Mesh Size =", MeshSize)
Output
SimLab Automation
Mesh Size = 3
Comments
Comments start with a # and extend to the end of line. For multi-line comment insert # at each line.
# This is a comment
Expression in Python Interpreter
In python interpreter, you can simply type the expression directly and it will write out the value.
3*2
Output
6
Indentation
Python uses indentation to identify the block of the code.
Variables
There is no explicit command for declaring a variable. It is created the moment a value is assigned to it.
GroupName = "Fillet_Faces"
NumLayers = 3
MeshSize = 1.5
You can also assign values in a line as
below:
GroupName, NumLayers, MeshSize = "Fillet_Faces", 3, 1.5
To assign the same value to multiple variables
x = y = z = 0
Object Type
To find type of any object use type() function.
GroupName, NumLayers, MeshSize = "Fillet_Faces", 3, 1.5
print(type(GroupName))
print(type(NumLayers))
print(type(MeshSize))
Output
<class 'str'>
<class 'int'>
<class 'float'>