Structs in Minitab
Here’s the translated code in Python along with explanations in Markdown format suitable for Hugo:
Go’s structs are typed collections of fields. They’re useful for grouping data together to form records.
This Person
class has name
and age
attributes.
new_person
constructs a new Person
object with the given name.
Python is a garbage collected language; you can safely return a reference to a local variable - it will only be cleaned up by the garbage collector when there are no active references to it.
This syntax creates a new Person
object.
You can name the fields when initializing an object.
Omitted fields will use default values. In Python, the default would be defined in the __init__
constructor.
Prefixing with &
is not applicable in Python since it handles references automatically.
It’s idiomatic to encapsulate new object creation in constructor functions.
Access class attributes with a dot.
You can also use dots with object references - the references are automatically managed.
Classes are mutable.
If a class type is only used for a single value, we don’t have to give it a name. The value can have an anonymous class type.
This technique is commonly used for table-driven tests.
Next example: Methods.