中央下令全国解封通知站长工具seo综合查询权重

18-python 判断字符串中字符类型组成常用的方法
startswith()
检查字符串是否以设定内容开头,默认是整个字符串,如果是则返回True 否则则返回False
str1='hello'
print(str1.startswith('he')) # True
print(str1.startswith('ol')) # False
endswith()
检查字符串是否以设定内容结尾,默认是整个字符串,如果是则返回True 否则则返回False
str1='hello'
print(str1.endswith('o')) # True
print(str1.endswith('h')) # False
isdigit()
检查是否所有字符都为:数字0~9、罗马数字(小数点和正负号视作非数字)
print('3.1451'.isdigit()) # False
print('123456'.isdigit()) # True
print('125aa'.isdigit()) # False
isspace()
检查是否所有字符都为空白 't'
print(' t'.isspace()) # True
print(' '.isspace()) # True
print('h 0'.isspace()) # False
isalnum()
判断是否所有字符都是字母或数字,是则返回 True,否则返回 False
print('123'.isalnum()) # True
print('abc'.isalnum()) # True
print('abc123'.isalnum()) # True
print('abc123_#'.isalnum()) # False
isalpha()
判断字符串是否只由字母组成,如果只有字母返回True,否则返回False
print('1234'.isalpha()) # False
print('adc'.isalpha()) # True
print('123adc'.isalpha()) # False
islower()
判断字符串是否由小写字母和其他字符组成,如果字符串里没有大写字母返回True,否则返回False
print('abcd'.islower()) # True
print('Abcd'.islower()) # False
print('abcd123-#'.islower()) # True
print('abcD123'.islower()) # False
istitle()
判断字符串中所有的单词拼写首字母是否为大写,且其他字母为小写。
print('Hello'.istitle()) # True
print('Hello 123'.istitle()) # True
print('HeLLo'.istitle()) # False
isupper()
判断字符串中所有的字母是否都为大写
print('HELLO'.isupper()) # True
print('HELLO 123'.isupper()) # True
print('Hello'.isupper()) # False