Match the start of a string
Check the letters at the start of the text. The result is true only when those letters match.
String.startswith
Simple example
Does abc start with a?
Start'abc' · 'a'
ResultTrue
def main() raises:
print(String("abc").startswith("a"))
True
Advertisements
Everyday examples
Child tickets start with C-. Is this a child ticket?
Start'C-18' · 'C-'
ResultTrue
def main() raises:
print(String("C-18").startswith("C-"))
True
Express parcels start with EX. Should this parcel go in the express tray?
Start'BX42' · 'EX'
ResultFalse
def main() raises:
print(String("BX42").startswith("EX"))
False
Is this shelf in the LAB section?
Start'LAB-3' · 'LAB'
ResultTrue
def main() raises:
print(String("LAB-3").startswith("LAB"))
True