Tuesday, 2 July 2019

Enumerations

Enumerations comes under User defined data types

The Python documentation describes an enum like this: An enumeration is a set of symbolic names (members) bound to unique, constant values. Within an enumeration, the members can be compared by identity, and the enumeration itself can be iterated over


>>> from enum import Enum
>>> class Person(Enum):
raj=1
sita=2
laxman=3


>>> print(Person.raj)
Person.raj
>>> 

Properties of enum:

1. Enums can be displayed as string or repr.
2. Enums can be checked for their types using type().
3. “name” keyword is used to display the name of the enum member.


You may like the following programs:


No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...