Why list does not accept [01,02,03,04] [closed]

-5

I'm starting in Python, I want to create a list of numbers, I wanted to use

dezenas = [[01,02,03,04],[05,06,07,08],[09,10,11,12],[13,14,15,16],[17,18,19,20],
           [21,22,23,24],[25,26,27,28],[29,30,31,32],[33,34,35,36],[37,38,39,40],
           [41,42,43,44],[45,46,47,48],[49,50,51,52],[53,54,55,56],[57,58,59,60],
           [61,62,63,64],[65,66,67,68],[69,70,71,72],[73,74,75,76],[77,78,79,80],
           [81,82,83,84],[85,86,87,88],[89,90,91,92],[93,94,95,96],[97,98,99,00]]

It is giving error when it starts with exemplo[01] , can someone help me!

    
asked by anonymous 04.11.2018 / 01:00

1 answer

16

"It gives error because it is wrong": D

Python 2

In Python 2, its syntax would be wrong, because numbers prefixed by% with% would be octal, and there would be no octal 0 (valid octal digits are 0 to 7).

In addition, the results probably would not be what you'd expect if you used it in situations like 027, for example. See this print in Python 2:

>>> print 027 + 3
26

This is because 027 in octal equals 23 in decimal.


Python 3

In Python 3, to avoid this confusion, it was decided not to accept the zero prefix, forcing the programmer to explicit an octal in this way: 08 , thus eliminating ambiguities.

In this way, a sequence of numbers beginning with zero is an invalid token. Except decimals as 0o27 - which curiously agree to be written as 0.82 .

I think that at this point in the championship you may have noticed that the solution is not to invent fashion, and to represent the numbers as they are:

dezenas = [[ 1, 2, 3, 4],[ 5, 6, 7, 8],[ 9,10,11,12] ...

You can use a space to align, if that's the problem.

    
04.11.2018 / 11:46