str.endswith(suffix[, start[, end]])
Built-in Types
https://docs.python.org/3/library/stdtypes.html
内置类型
https://docs.python.org/zh-cn/3/library/stdtypes.html
1. str.endswith(suffix[, start[, end]])
Return True if the string ends with the specified suffix, otherwise return False. suffix can also be a tuple of suffixes to look for. With optional start, test beginning at that position. With optional end, stop comparing at that position.
如果字符串以指定的 suffix 结束返回 True,否则返回 False。suffix 也可以为由多个供查找的后缀构成的元组。如果有可选项 start,将从所指定位置开始检查。如果有可选项 end,将在所指定位置停止比较。
suffix - 该参数可以是一个字符串或者是一个元素。
start - 字符串的开始位置。
end - 字符串的结束位置。
start 参数以 0 为第一个字符索引值。
end 参数以 1 为第一个字符索引值。
2. Example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import os
import sys
import numpy as np
import tensorflow as tf
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
current_directory = os.path.dirname(os.path.abspath(__file__))
print(16 * "++--")
print("current_directory:", current_directory)
print(16 * "++--")
string_number = "0123456"
print(string_number.endswith('456', 0, 6))
print(string_number.endswith('456', 0, 7))
/usr/bin/python2.7 /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow/yongqiang.py
++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--
current_directory: /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow
++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--
False
True
Process finished with exit code 0
3. Example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import os
import sys
import numpy as np
import tensorflow as tf
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
current_directory = os.path.dirname(os.path.abspath(__file__))
print(16 * "++--")
print("current_directory:", current_directory)
print(16 * "++--")
string_number = "cheng yong qiang"
print(string_number.endswith('g'))
print(string_number.endswith('ang'))
print(string_number.endswith('ang', 6))
print(string_number.endswith('ang', 11, 15))
print(string_number.endswith('ang', 11, 16))
/usr/bin/python2.7 /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow/yongqiang.py
++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--
current_directory: /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow
++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--
True
True
True
False
True
Process finished with exit code 0