Python 문자열 startswith() 메서드
예시
문자열이 "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)