Skip to content

Is Digit

Determine if the given character is a digit or not.

Example

  • For symbol = '0', the output should be

    is_digit(symbol) = true
  • For symbol = '-', the output should be

    is_digit(symbol) = false

Input/Output

  • [input] char symbol

    A character which is either a digit or not.

    Guaranteed constraints:Given symbol is from ASCII table.

Solution

py
def is_digit(symbol):
    return symbol.isdigit()


print(is_digit('-'))
js
// read the python version of this snippet from this folder
// and convert it to javascript

function isDigit(symbol) {
  return !isNaN(symbol);
}

my thoughts are neither my employer's nor my wife's