Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们可以在 C 中执行如下操作:
struct teams { char team_name[100]; int team_point[100]; } struct teams teams1[100];
我们以这种方式获得结构数组,在 Python 中是否有可能?谢谢
class Team(object): def __init__(self, name, points): self.name = name self.points = points teams = [] teams.append(Team('Chicago Bulls', [85, 75, 93, 10]))
由于 Python 是动态的,因此没有什么可以阻止您为对象属性分配任意值(对象实例的行为大多类似于命名空间),但是缺少一个对类型不匹配大喊大叫的迂腐编译器有一些优势。