Метод Python String начинается с()
Пример
Проверьте, начинается ли строка с «Hello»:
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)