TypeError: ord()需要一个字符,但找到长度为2的字符串

我遇到了一个棘手的问题。

TypeError: ord() expected a character, but string of length 2 found

我的代码:

    for c in input_s:
        if ord('a') <= ord(c.lower()) <= ord('z'):
            e_count += 1

我期望for c in input_s,即stringc always字符被赋值。这种情况很少发生,因此很难重新生成问题。是否存在c变量包含length2字符串的情况?

转载请注明出处:http://www.sthongjia.com/article/20230526/1401440.html