The documentation states:

An array that represents the months of the year in the current locale. This follows normal convention of January being month number 1, so it has a length of 13 and month_name[0] is the empty string.

Is this level of skeuomorphism warranted? Or is it confusing and potentially bug prone to start an array of expected values with no value?


It's better (and less confusing) to have the empty [0] placeholder at the beginning of the array so that you can just plug the month directly into the array indexer, than it is to start January at month 0 and have to perform a bit of conversion math to get the correct array index each time.

Sensible date implementations should not allow a month zero. Note that, for historical reasons, arrays typically start at an array index of zero.

  • Should it be '' rather than None, though? The latter would cause noticeable trouble more quickly if something did end up accessing month_name[0]. – jonrsharpe Aug 18 '15 at 9:26
  • You can put whatever you want there. – Robert Harvey Aug 18 '15 at 14:38
  • Why not overload the [] function such that month_name[0] throws an error? – Adam Ashwal Aug 18 '15 at 20:55
  • That's probably a good idea. – Robert Harvey Aug 18 '15 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.