endswith方法判断字符串是否以指定后缀结尾。
语法
S.endswith(suffix[, start[, end]]) -> bool
参数
返回值
示例
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.