python中isupper是什么意思_Python string isupper()用法及代码示例

Python在其库中具有许多实用程序功能,这些功能始终可以帮助我们完成一些日常工作。让我们来看看字符串的工作原理isupper()该方法实际上检查字符串中的所有字符是否均为大写。

用法: string.isupper()

参数:没有

返回:如果字符串中的所有字母均为大写,则为true;如果甚至其中之一为小写,则为False。

代码1:演示isupper()的工作

# Python3 code to demonstrate

# working of isupper()

# initializing string

isupp_str = "GEEKSFORGEEKS"

not_isupp = "Geeksforgeeks"

# Checking which string is

# completely uppercase

print ("Is GEEKSFORGEEKS full uppercase ?:" + str(isupp_str.isupper()))

print ("Is Geeksforgeeks full uppercase ?:" + str(not_isupp.isupper()))

输出:

Is GEEKSFORGEEKS full uppercase ?:True

Is Geeksforgeeks full uppercase ?:False

实际应用:此功能可以以多种方式使用,并且具有许多实际应用。一种这样的应用程序,用于检查大写字母,检查缩写(通常为大写字母),检查需要所有大写字母的句子的正确性。下面展示的是一个小示例,显示了isupper()方法的应用。

代码2:演示isupper()的实际应用

# Python3 code to demonstrate

# application of isupper()

# checking for abbreviations.

# short form of work/phrase

test_str = "Cyware is US based MNC and works in IOT technology"

# splitting string

list_str = test_str.split()

count = 0

# counting upper cases

for i in list_str:

if (i.isupper()):

count = count + 1

# printing abbreviations count

print ("Number of abbreviations in this sentence is:" + str(count))

输出:

Number of abbreviations in this sentence is:3

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值