s.isalnum() #全部字符都是数字或者字母,为真返回 Ture,不然返回 False。 s.isalpha() #全部字符都是字母,为真返回 Ture,不然返回 False。 s.isdigit() #全部字符都是数字(整数),为真返回 Ture,不然返回 False。 s.islower() #全部字符都是小写,为真返回 Ture,不然返回 False。 s.isupper() #全部字符都是大写,为真返回 Ture,不然返回 False。 s.istitle() #全部单词都是首字母大写,为真返回 Ture,不然返回 False。 s.isspace() #全部字符都是空白字符,为真返回 Ture,不然返回 False。
若是要判断是否是浮点数,能够用异常捕获(这个彷佛简单些),另外一种是用正则表达式:git
str = input("please input the number:") try: f = float(str) except ValueError: print("输入的不是数字!")