As I already mentioned, you should only store objects with the same properties in lists, even though you can store anything you want there in Python. However, the code becomes unreadable if you do this. To store different properties of an object, you should define a class. To do this, we start with data classes, which are intended to store data and no methods. Though you can do pretty much everything you want in Python, you can also create data classes containing methods (functions inside a class).

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Classes

  • Marco Gähler

摘要

As I already mentioned, you should only store objects with the same properties in lists, even though you can store anything you want there in Python. However, the code becomes unreadable if you do this. To store different properties of an object, you should define a class. To do this, we start with data classes, which are intended to store data and no methods. Though you can do pretty much everything you want in Python, you can also create data classes containing methods (functions inside a class).