【发布时间】:2018-03-28 11:40:07
【问题描述】:
你能建议用python表示这个结构的简洁方法吗?
students = struct;
students(1).fname = 'john';
students(1).lname ='smith';
students(1).height = 180;
students(2).fname = 'dave';
students(2).lname = 'clinton';
students(2).height = 184;
谢谢!
【问题讨论】:
-
词典列表或学生班级列表
-
你能举个例子吗?
-
我刚刚编写了一个类(名为“tree”),可以在 python3 中使用类似 matlab 的语法。对于最初的例子,我们可以这样写:students = tree() students.john.lname ='smith'students.john.height = 180 students.dave.lname = 'clinton'students.dave.height = 184 个学生。 other.lname = 'roger' students.other.height = 185 如果有人对“tree”类的源代码感兴趣,请告诉我。