checking if a letter is present in a string in python

This question already has an answer here:

  • Does Python have a string 'contains' substring method? 13 answers

  • >>> '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
    
    链接地址: http://www.djcxy.com/p/9390.html

    上一篇: 如何找到一个字符串空间内的字符串不敏感?

    下一篇: 检查一个字母是否存在于python中的字符串中