Write an expression that returns True if the str associated with s ends with “ism”. using python?

Answer 1

The most direct solution is brutally simple:

s.endswith(“ism”)

Python strings have endswith and startswith methods.

Answer 2

you just need a regular expression like this one:

‘@[email protected]’

the @ signs are delimiters, saying “the regular expression is everything between these”
we look for the string ‘ism’
and we use $ to say “after ism, this must be the end of the string”

so take your string, s and check it against that regex, return true if it matches and false otherwise

Leave a Comment