Python - Class Empty Class


The following statement makes a class with no attributes attached, an empty namespace object:

class rec: pass              # Empty namespace object 

After we make the class by running this statement, we can attach attributes to the class by assigning names to it completely outside of the original class statement: = 'Bob'             # Just objects with attributes 
rec.age  = 40 

And, we can fetch them with the usual syntax.

When used this way, a class is roughly similar to a "struct" in C.

It's an object with field names attached to it:

print(              # Like a C struct or a record 

Related Topic