Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Str.contains function help

can someone give example how to use str.contains() function in programmaticon V

i mean in python language

because in programmaticon V books only show how to use str.contains() in javaScript language

JavaScript very important to say JavaScript and not Java, and it’s str.includes() in Javascript, so it must be showing you the Python version. :slight_smile:

you don’t need to use str.contains you can just use the in keyword. for example

word = "hello"
search = "h"
if search in word:
    return True
return False

this would return True because the letter h is in word. Otherwise, like in this example

word = "hello"
search = "a"
if search in word:
    return True
return False

this will return False because the letter a is not in word

return search in word you don’t even have to put the if.

good point it will return a boolean

@CryptiCrystal’s function doesn’t work, use mine:

def contains (word, letters):
    for i in range(len(word)):
        e = None
        for j in range(len(letters)):
            if word[i + j] == letters[j]:
                continue
            e = 0
            break
        if e == None:
            return True
    return False

:slight_smile: (no offense @CryptiCrystal)

thank you so much @moonwatcher348 @CryptiCrystal solved

this is literally the same thing but it’s just not as neat

But your function doesn’t work as I said in Echo of war- string.contains() not working