九州体育网 - 十年信誉网站

关于作者

Discuss / Python / 作业

作业

Topic source

GOGOGO-枼子

#1 Created at ...

from enum import Enum, unique

Gender = Enum('Gender', ('Male', 'Female'))

class Student(object): def init(self, name, gender): self.name = name self.gender = gender

#测试 bart = Student('Bart', Gender.Male) if bart.gender == Gender.Male: print('测试通过!') else: print('测试失败!')

print(bart.gender)

lisa = Student('Lisa', Gender.Female) if lisa.gender == Gender.Female: print('测试通过!') else: print('测试失败!')

print(lisa.gender)

for gen, member in Gender.members.items(): print(gen, '=>', member)

#结果 测试通过! Gender.Male 测试通过! Gender.Female Male => Gender.Male Female => Gender.Female


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.