Bottom Page

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?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#2
I've had to deal with a broader range of number formats before. I just made new functions to validate/convert them.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
did you make validation functions totally separate from conversion function?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#4
I don't remember.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#5
i now try to make one function do both roles. unless fail= is specified, a failure raises an exception.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)