zoukankan      html  css  js  c++  java
  • Python3.x:判断字符串是否为全数字、英文、大写、小写、空白字符

    Python3.x:判断字符串是否为全数字、英文、大写、小写、空白字符

    判断接字符串是否为数字:

    str = raw_input("please input the number:")
    if str.isdigit():
    #为True表示输入的所有字符都是数字,否则,不是全部为数字
    
    #str为字符串
    #str.isalnum() 所有字符都是数字或者字母
    #str.isalpha() 所有字符都是字母
    #str.isdigit() 所有字符都是数字
    #str.islower() 所有字符都是小写
    #str.isupper() 所有字符都是大写
    #str.istitle() 所有单词都是首字母大写,像标题
    #str.isspace() 所有字符都是空白字符、	、
    、
    

    上述的主要是针对整型的数字,但是对于浮点数来说就不适用了,浮点数判断(正则表达式),例如:

    #引用re正则模块
    import re
    float_number ="3232.232d"
    #调用正则
    value = re.compile(r'^[-+]?[0-9]+.[0-9]+$')
    result = value.match(float_number)
    if result:
        print("Number is a float.")
    else:
        print("Number is not a float.")

     

  • 相关阅读:
    Mootools中的Class应用
    预初始化对象(OnPreInit)
    新博客开张
    ASP.NET获取客户端相关信息
    UpdatePannel中JS不执行问题
    KU990 JVAVA修改全屏
    textbox 增加click事件
    JS引用顺序的问题
    传统三层架构
    ORCALE 相关操作
  • 原文地址:https://www.cnblogs.com/lizm166/p/8690474.html
Copyright © 2011-2022 走看看