当前分类:300例题>>正文

Python示例:检查字符是否大写

来源:互联网   更新时间:2023年6月20日  

Python 示例

写一个 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
本文固定链接:https://6yhj.com/leku-p-4343.html  版权所有,转载请保留本地址!
[猜你喜欢]

标签: 百度统计