【问题标题】:Check whether a character is an alphabet, digit or special character- PYTHON检查字符是否是字母、数字或特殊字符 - PYTHON
【发布时间】:2022-08-11 01:20:06
【问题描述】:

Ques - 检查字符是字母、数字还是特殊字符

我已经编写了一个 python 代码解决方案,它运行良好。但是当我输入 (\"@\") 时,我得到的输出是字母而不是特殊字符。有人可以告诉我为什么以及如何为@解决它。

inp = input(\"Enter anything : \")
if inp >= \"a\" and inp <= \"z\" or inp >= \"A\" and inp <= \"Z\":
   print(\"input is alphabet\")
elif inp>=\"0\":
   print(\"input is number\")
else:
   print(\"special character\")

    标签: python if-statement special-characters control-flow alphabet


    【解决方案1】:
    elif inp>="0" and inp<="9":
       print("input is number")
    

    您需要指定数字集的结尾。 其他一切都应该保持不变。

    【讨论】:

      猜你喜欢
      • 2011-08-08
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      • 1970-01-01
      • 2010-12-20
      • 2014-11-25
      • 1970-01-01
      相关资源
      最近更新 更多