Skip to main content

get_digit

Given a whole number, return the requested digit of it, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Return the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is always an integer.

def get_digit(
value: Any,
arg: Any
) - > int

Given a whole number, return the requested digit of it, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Return the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is always an integer.

Parameters

NameTypeDescription
valueAnyThe whole number from which a digit will be extracted.
argAnyThe 1-based index of the digit to retrieve, counting from right to left.

Returns

TypeDescription
intThe specific digit requested from the input number, or 0 if the index is out of range, or the original value if inputs are invalid.