写一个 Python 程序,用一个实例来检查字符是否大写。
使用映射函数检查字符是否大写的 Python 程序
在这个 Python 示例中,我们使用 isupper 字符串函数来检查给定字符是否大写。
# Python Program to check character is Uppercase or not
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 大写字符或不输出
Please Enter Your Own Character : I
The Given Character I is an Uppercase Alphabet
>>>
Please Enter Your Own Character : j
The Given Character j is Not an Uppercase Alphabet
Python 程序查找字符是否大写
这个 python 程序允许用户输入任何字符。接下来,我们使用 If Else 语句来检查用户给定的字符是否大写。这里, If 语句 (ch > = 'A '和 ch < = 'Z ')检查字符是否大于等于 A,如果为 TRUE 则小于等于 Z,为大写。否则,它不是大写字符。
# Python Program to check character is Uppercase or not
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 值验证字符是否大写的 Python 程序
在这段 Python 代码中,我们使用 ASCII 值来检查字符是否大写。
# Python Program to check character is Uppercase or not
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