Python sem-noob, can someone explain why this phonomena is found in 'Lists'

I am working on a small application that retrieves data from a list stored in a list, passes it through the init class, and then displays / allows the user to work. Everything went well until I tried to format the original “list” in IDLE so that it was easier to read (for me). so I would change from 9 to 09, from 8 to 08. etc. It was a simple form / interval change, and it broke the whole damn program, citing an "invalid token." This is WTF, I thought. So, I opened the interpreter and started typing:

>x = [5,5]  #Control

>x

[5, 5]

>>> y=[05,05]    #control2

>>> y

[5, 5]

>>> z = [05, "ge"]  #test. 'Integer', before string, apparantly works.


>>> z

[5, 'ge']

> a = ["ge", 09]  #test2. String, before 'integer', cocks things up.

SyntaxError: invalid token

>>> b= ["ge", 9]    #test3, this works fine.


>>> b


['ge', 9]

, ... ? python "", , , ?

+4
4

. 0, octal. 9 !

Python 2.7.6 
Type "help", "copyright", "credits" or "license" for more information.
>>> 09
  File "<stdin>", line 1
    09
     ^
SyntaxError: invalid token
>>> 011
9

, Python3 0- , , . Python3, 0o .

Python 3.3.3 
Type "help", "copyright", "credits" or "license" for more information.
>>> 09
  File "<stdin>", line 1
    09
     ^
SyntaxError: invalid token
>>> 011
  File "<stdin>", line 1
    011
      ^
SyntaxError: invalid token
>>> 0o11
9
>>> 0o9
  File "<stdin>", line 1
    0o9
     ^
SyntaxError: invalid token
>>>
+7

Python, . , , 0-7. ,

5 == 05
6 == 06
7 == 07
8 == 010
9 == 011
...
15 == 017
16 == 020
...
255 == 0377

, 0x , ( 0-9 a-f: 255 == 0xff)

+4

This is because python interprets the numbers 0before them as octal numbers , so 09it makes no sense.

If you change it, for example, to the following:

a = ["ge", 07]

everything is working fine.

+3
source

This is because if a digit starts with 0, it is considered an octal digit, and octal digits - only from0-7

Example

>>> 015 - 02   #which is obviously not what you'd expect for base10 integers
11
+2
source

Source: https://habr.com/ru/post/1535844/


All Articles