""" 所谓判断真假,返回的结果是布尔型数据类型: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因为全部都是空格