endswith()方斯洛伐克语法:
str.endswith(suffix[, start[, end]])
endswith()方法重回true,假如字符串以钦命后缀结尾,不然重临(False可选节制的杰出从给定的目录初步和甘休)。
语法
以下是endswith()方法的语法:
str.endswith(suffix[, start[, end]])
参数
返回值
固然字符串以钦点的后缀截止此方式再次回到true,不然重返false。
例子
上边包车型客车例证突显了endswith()方法的接受。
#!/usr/bin/python
str = "this is string example....wow!!!";
suffix = "wow!!!";
print str.endswith(suffix);
print str.endswith(suffix,20);
suffix = "is";
print str.endswith(suffix, 2, 4);
print str.endswith(suffix, 2, 6);
当大家运转方面包车型客车主次,它会生出以下结果:
True
True
True
False
endswith()方法再次来到true,若是字符串以钦定后缀结尾,否则再次来到(False可选节制的相配…
endswith()
方法用于判别字符串是或不是以钦赐后缀结尾,假诺以钦命后缀结尾重返True,不然再次回到False。可选参数”start”与”end”为寻觅字符串的开首与甘休地点。
假若字符串含有钦定的后缀再次回到True,不然重临False。
以下实例显示了endswith()方法的实例:
#!/usr/bin/python3
Str='Runoob example....wow!!!'
suffix='!!'
print (Str.endswith(suffix))
print (Str.endswith(suffix,20))
suffix='run'
print (Str.endswith(suffix))
print (Str.endswith(suffix, 0, 19))
如上实例输出结果如下:
True
True
False
False