unicode string equivalent of contain
There is no difference between str
and unicode
.
print u"ábc" in u"some ábc"
print "abc" in "some abc"
is basically the same.
The same for ascii and utf8 strings:
if k in s:
print "contains"
There is no contains()
on either ascii or uft8 strings:
>>> "strrtinggg".contains
AttributeError: 'str' object has no attribute 'contains'
What you can use instead of contains
is find
or index
:
if k.find(s) > -1:
print "contains"
or
try:
k.index(s)
except ValueError:
pass # ValueError: substring not found
else:
print "contains"
But of course, the in
operator is the way to go, it's much more elegant.