字符串-检测

1.isupper() 检测字符串是否都是大写字母组成

1 1 #isupper() 检测字符串是否都是大写字母组成
2 2 str1 = 'YOU HURT MY HEART DEEPLY!1314爱'
3 3 result = str1.isupper()
4 4 print(result)
5 5 #输出结果:True

 

2.islower() 检测字符串是否都是小写字母组成

1 1 #islower() 检测字符串是否都是小写字母组成
2 2 str1 = 'you hurt my heart deeply!1314爱'
3 3 result = str1.islower()
4 4 print(result)
5 5 #输出结果:True

 

3.istitle() 检测字符串是否符合标题要求

1 1 #istitle() 检测字符串是否符合标题要求
2 2 title = 'I Love Python'
3 3 result = title.istitle()
4 4 print(result)
5 5 #输出结果:True

 

4.isalnum() 检测字符串是否由数字和字母及文字组成

1 1 #isalnum() 检测字符串是否由数字和字母及文字组成
2 2 str1 = '我lovepython1314'
3 3 result = str1.isalnum()
4 4 print(result)
5 5 #输出结果:True

 

5.isalpha() 检测字符串是否由字母和文字组成

1 1 #isalpha() 检测字符串是否由字母和文字组成
2 2 str1 = 'ilovepython%语言'
3 3 result = str1.isalpha()
4 4 print(result)
5 5 #输出结果:False

 

6.isdigit() 检测字符串是否由10进制字符组成(数字)

1 1 #isdigit() 检测字符串是否由10进制字符组成(数字)
2 2 str1 = '01234567894546'
3 3 result = str1.isdigit()
4 4 print(result)
5 5 #输出结果:True

 

7.检测字符串是否由数字字符组成(数字)

1 1 #检测字符串是否由数字字符组成(数字)
2 2 str1 = '01234567894546'
3 3 result = str1.isnumeric()
4 4 print(result)
5 5 #输出结果:True

 

8.isspace() 检测字符串是是否由空白字符(不可见字符)组成

1 1 #isspace()
2 2 str1 = '     \n\r\t'
3 3 print(str1)
4 4 result = str1.isspace()
5 5 print(result)
6 6 #输出结果:True

 

9.startswith() 检测字符串是否以指定的字符串开头

1 1 #startswith() 检测字符串是否以指定的字符串开头
2 2 str1 = 'python是目前流行排行榜榜首的一种语言!'
3 3 result = str1.startswith('python')
4 4 print(result)
5 5 #输出结果:True

 

10.endswith()检测字符串是否以指定的字符串结尾

1 1 #endswith()检测字符串是否以指定的字符串结尾
2 2 str1 = 'python是目前流行排行榜榜首的一种语言!'
3 3 result = str1.endswith('')
4 4 print(result)
5 5 #输出结果:True

 

转载于:https://www.cnblogs.com/lws865/p/10843896.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值