Computer Science

Carefully look at the following code and its execution on Python shell. Why is the last assignment giving error ?


>>> a = 0o12
>>> print(a)
10
>>> b = 0o13
>>> c = 0o78
    File "<python-input-41-27fbe2fd265f>", line 1
    c = 0o78
         ^
SyntaxError : invalid syntax         

Python Funda

12 Likes

Answer

Due to the prefix 0o, the number is treated as an octal number by Python but digit 8 is invalid in Octal number system hence we are getting this error.

Answered By

8 Likes


Related Questions