当前位置: 首页> 文旅> 艺术 > 派森学长带你学python—字符串(4)

派森学长带你学python—字符串(4)

时间:2025/8/27 13:48:23来源:https://blog.csdn.net/m0_52698295/article/details/141283878 浏览次数:0次

数据的验证


对输入数据的合法性进行验证,可应用于密码验证。

数据的验证:对输入数据的合法性进行验证
'''
#str.isdigit()所有数字都是阿拉伯数字(1)
print('123'.isdigit())
print('一二三'.isdigit())
print('0b1010'.isdigit())
print('I、II、III'.isdigit())
print('壹、贰、叁'.isdigit())
'''
True
False
False
False
False
'''
#str.isnumeric所有数字都是数字(2)
print('123'.isnumeric())
print('一二三'.isnumeric())
print('0b1010'.isnumeric())
print('ⅠⅡⅢ'.isnumeric())
print('壹贰叁'.isnumeric())
'''
True
True
False
True
True
'''
#str.isalpha()所有字符都是字母(包含中文字符)(3)
print('helllo你好'.isalpha())#True
print('hello你好2024'.isalpha())#False
#str.isalnum()所有字符都是数字或字母(4)
print('helllo你好'.isalnum())#True
print('hello你好2024'.isalnum())#True
#str.islower()所有字符都是小写(5)
print('HelloWorld'.islower())
print('helloworld'.islower())
print('hello你好'.islower())
'''
False
True
True
'''
#str.isupper()所有字符都是大写(6)
print('HelloWorld'.isupper())
print('HELLOWORLD'.isupper())
print('hello你好'.isupper())
'''
False
True
False
'''
#str.istitle()所有字符首字母必须大写,且大写字母只能是首字母(7)
print('Helloworld'.istitle())
print('helloWorld'.istitle())
print('HelloWorld'.istitle())
print('Hello World'.istitle())
'''
True
False
False
True
'''
#判断是否都是空白字符
print('\t'.isspace())
print(' '.isspace())
print('\n'.isspace())
'''
True
True
True
'''
关键字:派森学长带你学python—字符串(4)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: