Python 字串 endswith() 方法
定義和用法
endswith()
方法如果字串以指定的值結尾,則返回 True,否則返回 False。
語法
string.endswith(value, start, end)
引數值
引數 | 描述 |
---|---|
value | 必需。要檢查字串是否以其結尾的值 |
start | 可選。一個整數,指定開始搜尋的位置 |
end | 可選。一個整數,指定結束搜尋的位置 |
更多示例
示例
檢查字串是否以短語“my world.”結尾
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
自己動手試一試 »
示例
檢查從位置 5 到 11 是否以短語“my world.”結尾
txt = "Hello, welcome to my world."
x = txt.endswith("my world.", 5, 11)
print(x)
自己動手試一試 »