20190827 Python 练习记录

>>> from enum import Enum
>>> Month=Enum('Month',('jan','feb','may','arp','jun'))
>>> for name ,member in Month.__members__.items():
    print(name,'=>',member,',',member.value)

    
jan => Month.jan , 1
feb => Month.feb , 2
may => Month.may , 3
arp => Month.arp , 4
jun => Month.jun , 5
>>> from enum import Enum
>>> month=Enum('month',('jan','feb','may','arp','jun'))
>>> for name ,member in Month.__members__.items():
    print(name,'=>',member,',',member.value)

    
jan => Month.jan , 1
feb => Month.feb , 2
may => Month.may , 3
arp => Month.arp , 4
jun => Month.jun , 5
>>> from enum import Enum,unique
>>> @unique
class Weekday(Enum):
    sum=0
    mon=1
    tue=2
    wed=3
    thu=4
    fri=5
    sat=6

    
>>> day1=Weekday.mod
Traceback (most recent call last):
  File "", line 1, in
    day1=Weekday.mod
  File "C:\python\lib\enum.py", line 346, in __getattr__
    raise AttributeError(name) from None
AttributeError: mod
>>> day1=Weekday.mon
>>> print(day1)
Weekday.mon
>>> print(Weekday.tue.value)
2
>>> print(Weekday(2))
Weekday.tue

你可能感兴趣的:(20190827 Python 练习记录)