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)