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 ??
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With