数据的验证

笔记

# isdigit()十进制的阿拉伯数字
print('123'.isdigit()) # True
print('一二三'.isdigit()) # False
print('0b1010'.isdigit()) # False
print('Ⅲ'.isdigit()) # False
print('-'*20)

# 所有字符都数字
print('123'.isnumeric()) # True
print('一二三'.isnumeric()) # True
print('0b1010'.isnumeric()) # False
print('Ⅲ'.isnumeric()) # True
print('壹贰叁'.isnumeric()) # True
print('-'*20)

# 所有字符都是字母(包含中文字符)
print('hello你好'.isalpha()) # True
print('hello你好123'.isalpha()) # False
print('hello你好一二三'.isalpha()) # True
print('hello你好Ⅲ'.isalpha()) # False
print('hello你好壹贰叁'.isalpha()) # True
print('-'*20)

# 所有字符都是数字或字母
print('hello你好'.isalnum()) # True
print('hello你好123'.isalnum()) # True
print('hello你好一二三'.isalnum()) # True
print('hello你好Ⅲ'.isalnum()) # True
print('hello你好壹贰叁'.isalnum()) # True
print('-'*20)

# 判断字符的大小写
print('HelloWorld'.islower()) # False
print('helloworld'.islower()) # True
print('hello你好'.islower()) # True

print('-'*20)
print('HelloWorld'.isupper()) # False
print('HELLOWORLD'.isupper()) # True
print('HELLO你好'.isupper()) # True
print('-'*20)

# 所有字符都是首字母大写
print('Hello'.istitle()) # True
print('HelloWorld'.istitle()) # False
print('Helloworld'.istitle()) # True
print('Hello World'.istitle()) # True
print('Hello world'.istitle()) # False
print('-'*20)

# 判断是否都是空白字符
print('\t'.isspace()) # True
print(' '.isspace()) # True
print('\n'.isspace()) # True





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值