{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "<small><small><i>\n", "All the IPython Notebooks in this example series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/90_Python_Examples/tree/main/07_Python_Advanced_examples)**\n", "</i></small></small>" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Python Program to Represent enum\n", "\n", "In this example, you will learn to represent enum.\n", "\n", "To understand this example, you should have the knowledge of the following **[Python programming](https://github.com/milaan9/01_Python_Introduction/blob/main/000_Intro_to_Python.ipynb)** topics:\n", "\n", "* **[Python Object Oriented Programming](https://github.com/milaan9/06_Python_Object_Class/blob/main/001_Python_OOPs_Concepts.ipynb)**" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-07-02T07:02:44.292185Z", "start_time": "2021-07-02T07:02:44.258984Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Day.MONDAY\n", "MONDAY\n", "1\n" ] }, { "data": { "text/plain": [ "'\\n>>Expected output:\\n \\n52.9\\n0.0\\n'" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Example 1: Using enum module\n", "\n", "from enum import Enum\n", "\n", "class Day(Enum):\n", " MONDAY = 1\n", " TUESDAY = 2\n", " WEDNESDAY = 3\n", "\n", "# print the enum member\n", "print(Day.MONDAY)\n", "\n", "# get the name of the enum member\n", "print(Day.MONDAY.name)\n", "\n", "# get the value of the enum member\n", "print(Day.MONDAY.value)\n", "\n", "'''\n", ">>Expected output:\n", " \n", "Day.MONDAY\n", "MONDAY\n", "1\n", "'''" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can refer to the official documentation of **[enum](https://docs.python.org/3/library/enum.html)** for more information." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }