字符串常用操作之判断

.startswith()

.endswith()

isdigit()

name='alex_SB'
print(name.endswith('SB')) #判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False,可选参数"start""end"为检索字符串的开始与结束位置
print(name.startswith('alex')) #判断字符串是否是以指定子字符串开头,如果是则返回 True,否则返回 False,如果参数 beg end 指定值,则在指定范围内检查
age=input('>>: ')
print(age.isdigit()) #判断字符串是否只由数字组成

 

posted @ 2020-05-03 09:23  huangjunlong  阅读(410)  评论(0)    收藏  举报