编写一个 Python 程序,使用 isupper() 函数和 ASCII 值以及实际示例检查字符是否为大写。
Python 程序使用 isupper 函数检查字符是否为大写
在此 Python 示例中,我们使用 isupper 字符串函数来检查给定字符是否为大写。
ch = input("Please Enter Your Own Character : ")
if(ch.isupper()):
print("The Given Character ", ch, "is an Uppercase Alphabet")
else:
print("The Given Character ", ch, "is Not an Uppercase Alphabet")

Python 程序查找字符是否为大写
这个 python 程序允许用户输入任何字符。接下来,我们使用 If Else 语句来检查用户输入的字符是否为大写。在这里,If 语句 (ch >= ‘A’ and ch <= ‘Z’) 检查字符是否大于或等于 A,并且小于或等于 Z,如果为 TRUE,则为大写。否则,它不是大写字符。
ch = input("Please Enter Your Own Character : ")
if(ch >= 'A' and ch <= 'Z'):
print("The Given Character ", ch, "is an Uppercase Alphabet")
else:
print("The Given Character ", ch, "is Not an Uppercase Alphabet")

使用 ASCII 值验证字符是否为大写
在此代码中,我们使用 ASCII 值来检查字符是否为大写。
ch = input("Please Enter Your Own Character : ")
if(ord(ch) >= 65 and ord(ch) <= 90):
print("The Given Character ", ch, "is an Uppercase Alphabet")
else:
print("The Given Character ", ch, "is Not an Uppercase Alphabet")
Please Enter Your Own Character : p
The Given Character p is Not an Uppercase Alphabet
>>>
Please Enter Your Own Character : T
The Given Character T is an Uppercase Alphabet