Find text inside a string
Look for a piece of text anywhere in a longer string. These examples match the letters exactly.
String.__contains__
Simple example
Does abc contain b?
Start'abc' · 'b'
ResultTrue
def main() raises:
print("b" in String("abc"))
True
Advertisements
Everyday examples
Does a ticket marked blue-zone include the word blue?
Start'blue-zone' · 'blue'
ResultTrue
def main() raises:
print("blue" in String("blue-zone"))
True
Does a shelf marked fruit contain the word milk?
Start'fruit' · 'milk'
ResultFalse
def main() raises:
print("milk" in String("fruit"))
False
Does the route name East Road include Road?
Start'East Road' · 'Road'
ResultTrue
def main() raises:
print("Road" in String("East Road"))
True