Today I am learning python and I have assign one int variable in console like this
zipcode = 02492
But it's return me error like this
SyntaxError: invalid token
Why so, I don't understand it? Please help me to solve this query.
The reason you're getting the error is because Python interprets a number starting with the digit 0
as octal (base 8). However, the only valid octal digits are 0-7, so the 9
in your zip code is seen as invalid. Additionally, if you're using Python 3, the format of octal literals was changed so they begin with 0o
now (a zero followed by the lowercase letter o), so you'd still get an error even if you tried to input zipcode = 02432
, which would be valid in Python 2.
Since a zip code doesn't need to mathematical operations performed on it, it would be best if it was stored as a string.