How to match two equal string with IF statement in python
Question: My Python code:

    
    
    import re
    
    output = "your test contains errors"    
    
    match2 = re.findall('(.* contains errors)',output)
    mat2 = "['your test contains errors'] "
    
    if match2 == mat2:
        print "PASS"
    

In the above python program, I have string in 'match2' and mat2. If it's same
it should print PASS.

I am not getting any error if I run this program. If I print "match2" and
"mat2" is giving the same equal output. but if I use "if match2 == mat2" is
not printing as 'PASS'.

Can anyone please help me to fix this.

Thanks in advance.

Thanks,

Kumar.


Answer: [`re.findall`](https://docs.python.org/2/library/re.html#re.findall) returns a
list, not a string. So `mat2` should be a list, too:

    
    
    mat2 = ['your test contains errors']
    

If you want to check `your test contains errors` in the string, you can use
`in` operator:

    
    
    if "your test contains errors" in output:
        print "PASS"
    

