w3resource

Python: Enum Exercises, Practice, Solution


This resource offers a total of 25 Python Enum problems for practice.It includes 5 main exercises, each accompanied by solutions, detailed explanations, and four related problems.

[An Editor is available at the bottom of the page to write and execute the scripts.]


1. Create an Enum object and show a member name and value

Write a Python program to create an Enum object and display a member name and value.

Sample data :
Member name: Albania
Member value: 355
Click me to see the sample solution


Iterate over an Enum class and display members and values

ber and their value.

Expected Output:
Afghanistan = 93
Albania = 355
Algeria = 213
Andorra = 376
Angola = 244
Antarctica = 672
Click me to see the sample solution


3. Display Enum member names ordered by their values

Write a Python program to display all the member names of an enum class ordered by their values.

Expected Output:
Country Name ordered by Country Code:
Afghanistan
Algeria
Angola
Albania
Andorra
Antarctica
Click me to see the sample solution


4. Get All Values from an Enum Class

Write a Python program to get all values from an enum class.

Expected output:
[93, 355, 213, 376, 244, 672]
Click me to see the sample solution


5. Get Unique Enumeration Values

Write a Python program to get unique enumeration values.

Expected Output:
Afghanistan = 93
Albania = 355
Algeria = 213
Andorra = 376
Angola = 244
Click me to see the sample solution


 

Python Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.