طريقة Python String endswith ()
مثال
تحقق مما إذا كانت السلسلة تنتهي بعلامة ترقيم (.):
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
التعريف والاستخدام
تقوم endswith()
الطريقة بإرجاع True إذا كانت السلسلة تنتهي بالقيمة المحددة ، وإلا False.
بناء الجملة
string.endswith(value, start, end)
قيمه المعامل
Parameter | Description |
---|---|
value | Required. The value to check if the string ends with |
start | Optional. An Integer specifying at which position to start the search |
end | Optional. An Integer specifying at which position to end the search |
مزيد من الأمثلة
مثال
تحقق مما إذا كانت السلسلة تنتهي بعبارة "my world".:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.")
print(x)
مثال
تحقق مما إذا كان الموضع 5 إلى 11 ينتهي بعبارة "عالمي".:
txt = "Hello, welcome to my world."
x = txt.endswith("my world.",
5, 11)
print(x)