What is an example of the not boolean?

what is the purpose of “not” boolean?

How would you code: If any character in the string s is something other that “A”, “C”, “T”, or “G”, return False; otherwise return True.

s = "ACCTGCCCQTTTTA .... 1 million characters.... AT"

There are probably dozens of ways to code it. Here’s one

def find_bad_char(s):
    for ch in s:
        if not ch in "ACGT":
            return False
    return True
9 Likes

In this case, what is ‘ch’? Also, I see that you’re very active in this, Patrick. Hats off to ya!

1 Like

I’ll take a crack at explaining for you.

In this case, ‘ch’ is referring to the characters in the string. He is using a “for loop” to iterate through each character in the string to check if it matches any of the characters “A”, “C”, “T”, or “G”.

‘ch’ is the variable Patrick assigned in the for loop to hold the temporary value of the character in the string he is iterating over.

3 Likes

What is the difference between if not ch in “ACGT”: vs if ch not in “ACGT”:"

def find_bad_char(s):
for ch in s:
if not ch in “ACGT”:
return False
return True

def find_bad_char(s):
for ch in s:
if ch not in “ACGT”:
return False
return True

1 Like

In terms of how they work, they are both functionally the same. The use of ‘not in’ is preferred according to PEP-8 because it is easier to read; it’s more like a real English sentence.

4 Likes