实现isNum()函数判定一个字符串是否属于整数、浮点数或复数

xiaoxiao2021-02-28  102

实现isNum()函数,参数为一个字符串,如果这个字符串属于整数、浮点数或 复数的表示,则返回True,否则返回False

用判定参数类型的type函数即可

随便写三个不同类型的数实现判定

def isNum(n): n=type(eval(n)) if n==type(1): return True elif n==type(1.0): return True elif n==type(1+1j): return True else: return False isNum(input("输入:"))

转载请注明原文地址: https://www.6miu.com/read-39195.html

最新回复(0)