首页 > 编程知识 正文

Python 程序:检查字符是否大写

时间:2023-11-24 15:33:39 阅读:308860 作者:BDCU

写一个 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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。