Python:判断输入的是否是数字
参考链接: https://www.cnblogs.com/zxmbky/p/9160822.html 代码: #!/usr/bin/python3 num1 = input ( "first num :" ) . strip ( ) num2 = input ( "second num: " ) . strip ( ) if not num1 . replace ( "." , '' ) . isdigit ( ) : exit ( "fist num not num !" ) if not num2 . replace ( "." , '' ) . isdigit ( ) : exit ( "second num not num !" ) sum = float ( num1 ) + float ( num2 ) print ( "sum :" , sum ) 执行情况: adams@adams : ~ $ python test . py first num : 12345.43456 second num : 1212 . .1212 ^ [ [ D ^ [ [ D ^ [ [ D second num not num ! adams@adams : ~ $ python test . py first num : 1212.1212 second num : 343434