How to find if a string contains another string
gherron at islandtraining.com
Tue Oct 30 05:08:48 CET 2007
Borse, Ganesh wrote:
> Am new to python.
> May someone please help me know this?
> How can we check whether one big string contains another small string?
> bigstring="python anaconda boa cobra"
Use the operator named in:
>>> bigstring="python anaconda boa cobra"
>>> smallone in bigstring
Often used in if statements like this:
>>> if smallone in bigstring:
... print 'contained'
... print 'not'
> If 0 == contains(bigstring,smallone):
> print "Yes, boa is snake.."
> Is there any function like "contains" or "exists" in python?
> What are different alternatives we have?
> Please help.
> Thanks and Regards,
> Please access the attached hyperlink for an important electronic communications disclaimer:
More information about the Python-list