Tuesday, May 12, 2026
HomeLanguagesenum.auto() in Python

enum.auto() in Python

With the help of enum.auto() method, we can get the assigned integer value automatically by just using enum.auto() method.

Syntax : enum.auto()

Automatically assign the integer value to the values of enum class attributes.

Example #1 :
In this example we can see that by using enum.auto() method, we are able to assign the numerical values automatically to the class attributes by using this method.




# import enum and auto
from enum import Enum, auto
  
# Using enum.auto() method
class language(Enum):
    Java = auto()
    Python = auto()
    HTML = auto()
  
print(list(language))


Output :

[,, ]

Example #2 :




# import enum and auto
from enum import Enum, auto
  
# Using enum.auto() method
class language(Enum):
    Cpp = auto()
    JavaScript = auto()
    Java = auto()
    Python = auto()
    HTML = auto()
  
print(list(language))


Output :

[,,,, ]

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS