تبدأ سلسلة Python بالطريقة ()
مثال
تحقق مما إذا كانت السلسلة تبدأ بـ "مرحبًا":
txt = "Hello, welcome to my world."
x = txt.startswith("Hello")
print(x)
التعريف والاستخدام
تقوم startswith()
الطريقة بإرجاع True إذا كانت السلسلة تبدأ بالقيمة المحددة ، وإلا False.
بناء الجملة
string.startswith(value, start, end)
قيمه المعامل
Parameter | Description |
---|---|
value | Required. The value to check if the string starts 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 |
مزيد من الأمثلة
مثال
تحقق مما إذا كان الموضع 7 إلى 20 يبدأ بالأحرف "wel":
txt = "Hello, welcome to my world."
x = txt.startswith("wel",
7, 20)
print(x)