美图齐众专注资阳网站设计 资阳网站制作 资阳网站建设
资阳网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

Python程序:检查字符是否是字母

创新互联python教程:

用一个实际例子写一个 Python 程序来检查字符是否是字母。

Python 程序检查字符是否是字母

这个 python 程序允许用户输入任何字符。接下来,我们使用 If Else 语句来检查用户给定的字符是否是字母表。这里 If 语句检查字符是在 A 和 z 之间还是在 A 和 z 之间,如果是 TRUE,则是字母表;否则,它就不是字母表。

# Python Program to check character is Alphabet or not
ch = input("Please Enter Your Own Character : ")

if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
    print("The Given Character ", ch, "is an Alphabet")
else:
    print("The Given Character ", ch, "is Not an Alphabet")

Python 字符是字母还是不输出

Please Enter Your Own Character : q
The Given Character  q is an Alphabet
>>> 
Please Enter Your Own Character : 8
The Given Character  8 is Not an Alphabet

Python 程序使用 ASCII 值验证字符是否是字母

在这个 Python 代码中,我们使用 If Else 语句中的 ASCII 值来检查字符是否是字母表。

# Python Program to check character is Alphabet or not
ch = input("Please Enter Your Own Character : ")

if((ord(ch) >= 65 and ord(ch) <= 90) or (ord(ch) >= 97 and ord(ch) <= 122)):
    print("The Given Character ", ch, "is an Alphabet")
else:
    print("The Given Character ", ch, "is Not an Alphabet")
Please Enter Your Own Character : W
The Given Character  W is an Alphabet
>>> 
Please Enter Your Own Character : #
The Given Character  # is Not an Alphabet

寻找字符的 Python 程序是使用 isalpha 函数的字母表

在这个例子 python 代码中,我们使用 isalpha 字符串函数来检查给定的字符是否是字母表。

# Python Program to check character is Alphabet or not
ch = input("Please Enter Your Own Character : ")

if(ch.isalpha()):
    print("The Given Character ", ch, "is an Alphabet")
else:
    print("The Given Character ", ch, "is Not an Alphabet")


文章名称:Python程序:检查字符是否是字母
标题路径:http://www.zsjierui.cn/article/dpshepp.html

其他资讯