>>> string = "Hello World"
>>> # Check Sub-String in String
>>> "World" in string
True
>>> # Check Sub-String not in String
>>> "World" not in string
False
fullstring = "StackAbuse"
substring = "tack"
if substring in fullstring:
print("Found!")
else:
print("Not found!")
if "blah" not in somestring:
continue
string = "This contains a word" if "word" in string: print("Found") else: print("Not Found")
myString = "<text contains this>"
myOtherString = "AnotherString"
# Casting to string is not needed but it's good practice
# to check for errors
if str(myString) in str(myOtherString):
# Do Something
else:
# myOtherString didn't contain myString
string = "My favourite programming language is Python"
substring = "Python"
if substring in string:
print("Python is my favorite language")
elif substring not in string:
print("Python is not my favourite language")
txt = "foobar"
print("foo" in txt)
any(not c.isalnum() for c in string)
str="Hello, World!"
print("World" in str) # True