0
点赞
收藏
分享

微信扫一扫

第六章 06 判断真假,操作方法的判断

天使魔鬼 2022-03-11 阅读 29
python
"""
所谓判断真假,返回的结果是布尔型数据类型:true或False.
startswith():检查字符串是否是以指定子串开头,是则返回Ture,否则返回False。如果设置开始和结束位置下标,则在指定范围内检查。
语法:
字符串序列.startswith(子串,开始位置下标,结束位置下标)
"""
mystr="hello world and itcast and itheima and Python"
print(mystr.startswith('hello'))
print(mystr.startswith('hells'))
print(mystr.endswith('Python'))

"""
1.isalpha():如果字符串至少有一个字符并且所有字符都是字母则返回True,否则返回False。
2.isdigit():如果字符串只包含数字则返回True否则返回False
3.isalnum():如果字符串至少有一个字符并且所有字符都是字母或数字则返回True,否则返回False。
4.isspace():如果字符串都是空格返回True否则返回False
"""
mystr="hello world and itcast and itheima and Python"
print(mystr.isalpha())#False因为有空格并不都是字母
mystr1='1245'
print(mystr1.isdigit())#Ture因为都是数字也没有空
print(mystr1.isalnum())#Ture因为都是数字
print(mystr.isalnum())#False因为有空格
print(mystr.isspace())#False因为有字母
mystr3='          '
print(mystr3.isspace())#True因为全部都是空格
举报

相关推荐

第六章 方法入门

第六章 容器

第六章:接口

第六章总结

PTA第六章

第六章 BOM

java第六章总结

0 条评论