checking if a letter is present in a string in python
本问题已经有最佳答案,请猛点这里访问。
如何检查字符串中是否存在字母"n"。例子:
1 2 3 | flag = False if string contains N: flag = True |
因此,如果字符串是
1 2 3 4 5 6 7 8 | >>> 'N' in 'PYTHON' True >>> 'N' in 'STACK OVERFLOW' False >>> 'N' in 'python' # uppercase and lowercase are not equal False >>> 'N' in 'python'.upper() True |
另外,在分配给您的
1 2 3 | flag = False if 'N' in your_string: flag = True |
做
1 | flag = 'N' in your_string |