1

I know the format for calling a value from list is a[0] or a[1].
When I tried for getting values as a[01] or a[06] and still got the answers.
But when getting value for a[08] or a[09], it throws syntax error.
Any idea why it is so?

>>> a = [1,2,6,8,9,22,3,44,5,67,11]
>>> a[05]
22
>>> a[09]
   File "<stdin>", line 1
   a[09]
      ^
   SyntaxError: invalid token
>>> a[08]
  File "<stdin>", line 1
  a[08]
     ^
 SyntaxError: invalid token
>>> a[07]
44
>>> a[8]
5
Vivek Kumar
  • 35,217
  • 8
  • 109
  • 132

1 Answers1

2

When starting a number with 0, it is assumed to be octal. So it is invalid when 8 or 9 is encountered here.

Have a look at the following answers:

Vivek Kumar
  • 35,217
  • 8
  • 109
  • 132