Enumeration in python


/ Published in: Python
Save to your folder(s)

Simple ways to get enumerations in python.


Copy this code and paste it in your HTML
  1. >>> Status = namedtuple('Status', 'open pending closed')._make(range(3))
  2. >>> Status.open, Status.pending, Status.closed
  3. (0, 1, 2)
  4.  
  5.  
  6. >>> class Status:
  7. open, pending, closed = range(3)
  8. >>> Status.open, Status.pending, Status.closed
  9. (0, 1, 2)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.