string contains and special characters
Mark Lawrence
breamoreboy at yahoo.co.uk
Tue Oct 9 10:50:26 EDT 2012
On 09/10/2012 15:23, Dave Angel wrote:
> On 10/09/2012 10:02 AM, loial wrote:
>> I am trying to match a string that containing the "<" and ">" characters, using the string contains function, but it never seems to find the lines containing the string
>>
>> e.g if mystring.contains("<TAG>") :
>>
>> Do I need to escape the characters...and if so how?
>>
>
> What language are you trying to use, and what version of that language?
> In all the Python versions I know of, that line would simply be a syntax
> error. There's no "contains" method in the str class, use the 'in' keyword.
I see you've already corrected youself :)
>
> if "<TAG>' in mystring:
>
> No need to escape any ASCII characters except backslash.
>
No need to escape anything if raw strings are used.
--
Cheers.
Mark Lawrence.
More information about the Python-list
mailing list