五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

關(guān)于Python的enum類型

2023-08-22 13:24 作者:李家鋪子掌柜  | 我要投稿

Did you have thought?of the questions as following:

  1. When and where to use?Enum?

  2. Why do we need?Enum? What are the advantages?

  3. What exactly is an?Enum?

Let's talk about the qustions that already answered respectively.

1. When and where to use enums?

  • When you have a variable that takes one of a limited set of possible values.

For example, the days of the week:

2. Why do we need enum? What are the advantages?

  • Enums are advantageous because they give a name to a constant, which makes code more readable; and because the individual members cannot be rebound, making Python Enums semi-constant (because the?Enum?itself could still be rebound).

  • Besides more readable code, debugging is also easier as you see a name along with the value, not just the value

  • Desired behavior can be added to Enums

For example, as anyone who has worked with the?datetime?module knows,?datetime?and?date?have two different representations for the days of the week: 0-6 or 1-7. Rather than keep track of that ourselves we can add a method to the?Weekday?enum to extract the day from the?datetime?or?date?instance and return the matching enum member:

3. What exactly is Enum?

  • Enum is a?type, whose members are named constants, that all belong to (or should) a logical group of values. So far I have created?Enums for:

FederalHoliday?is my most complex; it uses?this recipe, and has methods to return the actual date the holiday takes place on for the year given, the next business day if the day in question is a holiday (or the range of days skipped includes the holiday or weekends), and the complete set of dates for a year. Here it is:

本文轉(zhuǎn)自stackoverflow,希望對你有所幫助。


一起學(xué)習(xí),共同進步


關(guān)于Python的enum類型的評論 (共 條)

分享到微博請遵守國家法律
呼伦贝尔市| 黑龙江省| 南靖县| 色达县| 裕民县| 临海市| 中阳县| 家居| 云南省| 平定县| 化州市| 都江堰市| 昌吉市| 棋牌| 科技| 化德县| 尚志市| 遂溪县| 葵青区| 镇宁| 克拉玛依市| 阜康市| 寿宁县| 台南市| 阿克陶县| 历史| 长海县| 台湾省| 冀州市| 基隆市| 枣强县| 嘉兴市| 阿巴嘎旗| 吉林省| 司法| 峨边| 华蓥市| 荆门市| 澎湖县| 清水县| 平舆县|