"str.contains(part)" or alternatives?
sschwarzer at sschwarzer.net
Wed Sep 11 17:03:15 EDT 2002
Hi Steve :)
Steve Holden wrote:
>> >>> s = 'Hello'
>> >>> if s.contains('ll'):
>>Do you have other suggestions how to do the test easily without using special
>>values? Should a .contains method be part of string objects in future Python
>>versions? What do you think?
> I think the current proposal is to move to
> if ll in s:
> for this construct. Happy?
I would like .contains more, but at least the proposal is _much_ better than
"if s.find(part) != -1". :-)
"if part in s" disturbs the pattern "if item in sequence" somewhat but that has
already been weakened by "if key in dict" (that I like, nonetheless).
More information about the Python-list