Reputation: 10956
I have two strings: string1 = ABCDE
and string2 = BC
.
I hope to write a program returning a T/F value for whether string2 is contained in string1. For the example above, the function should return True. I know it's something like the %in%
function in R
, but since I am a newbie in Python, please share your thoughts on this simple question.
Thanks!
Upvotes: 0
Views: 3186
Reputation: 113950
if string1 in string2: print "YES!"
this is really easy in python ;)
Upvotes: 1
Reputation: 37249
You could try this:
def StringTest(string1, string2):
return string2 in string1
Or outside of a function:
result = string2 in string1
Either of these will return a boolean result.
Upvotes: 3