-1

I'm trying to run a simple program code which uses a variable representing an integer number.

fav_number = 07
print ("My favourite number is:",fav_number)

after running the code I got this error:

 File "C:\Users\Desktop\Chapter 2\numbers.py", line 7                                                                                                 
   fav_number = 07                                                                                                                                                     
             ^                                                                                                                                                      
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o 
prefix for octal integers
                                                       
 [Finished in 0.37s with exit code 1]

after looking on internet for solution I could only find that zero isn't allowed in start of an integer value? can someone some explain to me in much simpler way why it's not allowed and what's the solution to it?

Note: I'm beginner learner so I'd be thankful if someone gives me an additional basic explanation.

viveooo
  • 37
  • 7
  • @ErmiyaEskandary I need some more explanation in simpler words. It's my day 3 of learning python and I'm not understanding half of the things explained in that thread. Sorry for that. Thankyou for reply. – viveooo Apr 09 '22 at 12:53
  • 2
    Why is "don't write the leading zero" not a valid solution for you? – mkrieger1 Apr 09 '22 at 13:11
  • It's a feature of the Python language. Different languages have different rules for declaring values - whatever they might be. This is just such a case – DarkKnight Apr 09 '22 at 13:34

1 Answers1

0

it is just how the language is defined. it causes some ambiguity, as a leading 0 can be used to represent a hex value, so for integer values, it is not allowed.

Ritwick Jha
  • 340
  • 2
  • 10