0

I can't seem to comprehend the unusual behaviour here:

>>> 2_3_3_2
2332
>>> int("2_3_3_2")
2332

Why it doesn't throw an error in both the cases?

ankit
  • 3
  • 1
  • 11
  • 4
    https://www.python.org/dev/peps/pep-0515/ – Passerby Jan 17 '22 at 08:48
  • It *was* a syntax error up to Python 3.5. The PEP you have been referred to gives the reasons for the change. If you find this unexpected, it may be that your tutorial material is a bit out of date. If so, you should consider finding something newer. There have been other, far more important changes to Python since 3.5, notably ordering of `dict`s, and the introduction of `f`-strings. – BoarGules Jan 17 '22 at 09:42

1 Answers1

0

The use of underscores helps programmers read more easily large numbers https://www.python.org/dev/peps/pep-0515/.

clemsciences
  • 121
  • 9
  • Is it unique to Python? – ankit Jan 17 '22 at 08:51
  • 1
    @ankit "Is it unique to Python?" Did you read the link? In the very first section it says "This is a common feature of other modern languages" – Passerby Jan 17 '22 at 08:52
  • In complement, PEP 515 has been integrated in python since version 3.6: https://stackoverflow.com/questions/54009778/what-do-underscores-in-a-number-mean – hpchavaz Jan 17 '22 at 08:53