事の発端
pythonのisdigit()でマイナスの整数を判定しようとしたら、出来なかったので調査した。調査時間10分程度。
参考サイト
https://or3.hatenablog.com/entry/2017/10/08/034955
参考サイトを見たほうがいいです。
サンプルコード
def is_num(a):
try:
int(a)
except:
return False
return True
def main():
s = '-1'
print('s =', s)
print('isdecimal:', s.isdecimal())
print('isdigit:', s.isdigit())
print('isnumeric:', s.isnumeric())
print('is_num:', is_num(s))
if __name__ == "__main__":
main()
実行結果
感想
isdigitが残念すぎる。