7

How can I check if the letter "N" is present in a string. Example:

flag = False
if string contains N:
   flag = True

So flag = True if string is "CNDDDNTD" and flag = False if string is "CCGGTTT". I think re.search will work, but not sure of the options to use.

Steven Rumbalski
  • 44,786
  • 9
  • 89
  • 119
Ssank
  • 3,367
  • 7
  • 28
  • 34

1 Answers1

13
>>> 'N' in 'PYTHON'
True
>>> 'N' in 'STACK OVERFLOW'
False
>>> 'N' in 'python' # uppercase and lowercase are not equal
False
>>> 'N' in 'python'.upper()
True

Also, there is no need for a conditional statement when assigning to your flag. Rather than

flag = False
if 'N' in your_string:
   flag = True

do

flag = 'N' in your_string
Steven Rumbalski
  • 44,786
  • 9
  • 89
  • 119