python字符串-结尾判断(endswith)
2022/4/6 22:49:05
本文主要是介绍python字符串-结尾判断(endswith),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
endswith方法判断字符串是否以指定后缀结尾。
语法
S.endswith(suffix[, start[, end]]) -> bool
参数
- suffix: 指定的后缀字符串,也可以是一个元组。
- start: 可选参数,字符串的开始位置。
- end: 可选参数,字符串的结束位置。
返回值
- 包含指定后缀返回True,否则返回False。
示例
str = '我爱我的爸妈' print(str.endswith('妈')) print(str.endswith('爸妈')) print(str.endswith('爸')) print(str.endswith('爸', 0, len(str)-1)) # 可以使用元组作为参数,只要元组中包含结尾的字符串就返回True print(str.endswith(('爸', '妈')))
True True False True True
help()
Help on built-in function endswith: endswith(...) method of builtins.str instance S.endswith(suffix[, start[, end]]) -> bool Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.
这篇关于python字符串-结尾判断(endswith)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python