I have following function:
def calculate_digits(number: Union[int, float, str]) -> int:
absolute_value: float = abs(number)
rounded_value: int = math.floor(absolute_value)
total_digits_needed: int = calculate_length_integer(rounded_value)
return total_digits_needed
As you can see, I want to use this for different python types : int, float, str...
As the abs() only works for floats I was wondering, how do I deal best with this?
Do I need to write a function with if, elsif statement to do this, or is there a better way to do this?
question from:
https://stackoverflow.com/questions/65871133/use-same-function-for-different-types 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…