Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,961 questions

51,903 answers

573 users

How to create (represent) an Enum in Python

2 Answers

0 votes
from enum import Enum

Programming = Enum('Programming', 'python java c_sharp php c')

print(Programming.python)

print(Programming['java'])

print(Programming.php.name)
print(Programming.c_sharp.name)

print(Programming.java.value)
print(Programming.python.value)


'''
run:

Programming.python
Programming.java
php
c_sharp
2
1

'''

 



answered Nov 3, 2017 by avibootz
edited Nov 3, 2017 by avibootz
0 votes
from enum import Enum


class Colors(Enum):
    red = 1
    green = 2
    blue = 3
    cyan = 4


print(Colors.red)
print(Colors.green)

print(Colors['blue'])

print(Colors.cyan.name)

print(Colors.red.value)
print(Colors.blue.value)


'''
run:

Colors.red
Colors.green
Colors.blue
cyan
1
3

'''

 



answered Nov 3, 2017 by avibootz

Related questions

1 answer 316 views
1 answer 220 views
2 answers 270 views
1 answer 123 views
1 answer 115 views
115 views asked Aug 29, 2023 by avibootz
...