string.startswith
Defined in module
"string"from "string" import startswithReturns whether str begins with prefix.
Parameters
str | string | the string to test |
prefix | string | the prefix to look for |
Return value
true when the first prefix.len() characters of str equal prefix, false otherwise.
Notes
An empty prefix always matches: every string starts with the empty string. A prefix longer than str cannot match and gives false without reading past the end of str.
The comparison is a raw byte compare; there is no case-insensitive form.
Example
from "string" import startswith
println("startswith(\"hello world\", \"hello\") =", startswith("hello world", "hello"))
println("startswith(\"hello\", \"hello world\") =", startswith("hello", "hello world")) // prefix longer than str: always false
// the empty prefix always matches
println("startswith(\"anything\", \"\") =", startswith("anything", ""))Output:
startswith("hello world", "hello") = true
startswith("hello", "hello world") = false
startswith("anything", "") = trueSee also
endswith | Returns whether str ends with suffix. |
| string | module index |