Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typecasting not works for 08 and 09

While typecasting in python I got an error.

int(01)
int(02)
int(03)
int(04)
int(05)
int(06)
int(07)

Above all works fine.

But when I do same for bellow -:

int(08)

and

int(09)

I am getting error i.e

SyntaxError: invalid token

I know, this typecasting is not correct for converting int to int.

But I just want to know, when it works for 01 to 07, then why it is not working for 08 and 09 only ??

like image 312
Nilesh Avatar asked Dec 19 '22 21:12

Nilesh


1 Answers

Numbers starting with 0 are considered as octal data. Octal numbers can't have number more than 7.

To fix this, you can convert the data to string and pass the base explicitly like this

print int("09", 10)

Output

9
like image 50
thefourtheye Avatar answered Jan 04 '23 14:01

thefourtheye