创新互联Python教程:
为静海等地区用户提供了全套网页设计制作服务,及静海网站建设行业解决方案。主营业务为成都网站建设、网站设计、静海网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
写一个 Python 程序,通过一个实例,使用 islower 和 isupper 检查字符是小写还是大写。
在这个 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 程序允许用户输入任何字符。接下来,我们使用 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 值来检查字符是大写还是小写。
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
文章名称:Python程序:检查字符是小写还是大写
URL链接:http://www.36103.cn/qtweb/news22/1822.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联