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

Python示例:检查字符是小写还是大写

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

Python 示例

写一个 Python示例,通过一个实例,使用 islower 和 isupper 检查字符是小写还是大写。

使用 islower 和 isupper 函数检查字符是小写还是大写的 Python示例

在这个 Python 示例中,我们使用 islower 和 isupper 字符串函数来检查给定字符是小写还是大写。

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

if(ch.isupper()):
    print("The Given Character ", ch, "is an Uppercase Alphabet")
elif(ch.islower()):
    print("The Given Character ", ch, "is a Lowercase Alphabet")
else:
    print("The Given Character ", ch, "is Not a Lower or Uppercase Alphabet")

检查字符是否小写的 Python示例

这个 python 程序允许用户输入任何字符。接下来,我们使用 Elif 语句来检查用户给定的字符是小写还是大写。

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

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

Python 字符是小写还是大写输出

Please Enter Your Own Character : #
The Given Character  # is Not a Lower or Uppercase Alphabet
>>> 
Please Enter Your Own Character : T
The Given Character  T is an Uppercase Alphabet
>>> 
Please Enter Your Own Character : g
The Given Character  g is a Lowercase Alphabet

Python示例使用 ASCII 值检查字符是否为小写

在这段 Python 代码中,我们使用 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") 
elif(ord(ch) >= 97 and ord(ch) <= 122):
    print("The Given Character ", ch, "is a Lowercase Alphabet")
else:
    print("The Given Character ", ch, "is Not a Lower or Uppercase Alphabet")
Please Enter Your Own Character : o
The Given Character  o is a Lowercase Alphabet
>>> 
Please Enter Your Own Character : R
The Given Character  R is an Uppercase Alphabet
>>> 
Please Enter Your Own Character : $
The Given Character  $ is Not a Lower or Uppercase Alphabet
本文固定链接:https://6yhj.com/leku-p-4342.html  版权所有,转载请保留本地址!
[猜你喜欢]

标签: urllib