Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
underscore in numbers
#1
you can insert one (not more than one) underscore character in literals for int, float, and complex. conversion functions int(), float(), complex(), and decimal.Decimal() also support this form. for ints, this includes expressions in other bases, but not within the base prefix.

however, methods like .isdecimal(), .isdigit(), and .isnumeric() do not support this form. you could remove the underscore characters before performing the .is checks. but then, cases with invalid underscores, such as double, can leak through. if you do remove underscores to do checks, you should also remove them for the conversion. perhaps a simpler way is to just go directly to the conversion inside try/except.

i am considering using _ in output number formatting in certain cases (

anyone have experience dealing with any of this?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
underscore in numbers - by Skaperen - Jul-13-2019, 04:22 AM
RE: underscore in numbers - by ichabod801 - Jul-13-2019, 12:21 PM
RE: underscore in numbers - by Skaperen - Jul-13-2019, 10:31 PM
RE: underscore in numbers - by ichabod801 - Jul-14-2019, 01:04 AM
RE: underscore in numbers - by Skaperen - Jul-14-2019, 11:46 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020