On Sat, Oct 02, 2021 at 02:53:03AM -0000, Debashish Palit wrote: > There is no need of a three_way_flag - just use a conditional > expression instead of an if-elif-else block,
Of course you need a three way flag if your function returns a three way flag. It returns False for ints, True for floats, and None for anything else. So the caller needs to handle three cases: - your function returns True, so call float(s) - your function returns False, so call int(s) - your function returns None, so handle the string some other way. How else could you do it? > str.isfloat uses the int() and float() functions, Correct, which is why your function is wasteful and inefficient. If I call `isfloat('123')`, the function calls float, and throws the result away, so I have to call float *again*. So if people use this function, they are effectively doing: s = '123.0' # input is a string, from somewhere else float(s) # throw away the result num = float(s) > If int() raises overflow error int() never raises OverflowError. -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YAUF2HVTPLBAOCDZKM4WMYF3LWDDJLPF/ Code of Conduct: http://python.org/psf/codeofconduct/