.islower()、.isupper()、isdigit()、列表相减

本文介绍了Python中的三个字符串方法:`islower()`检查字符串全为小写,`isupper()`检查全为大写,`isdigit()`检查全为数字。同时展示了两种列表相减的方法:使用zip和lambda表达式实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

string.islower() 字符判断是不是小写字母
string.isupper() 字符判断是不是大写字母
string.isdigit() 字符判断是不是数字

# .islower():checks if all the characters in a string are lowercase.
text = "hello"
result = text.islower()
print(result)  # Output: True


# .isupper():checks if all the characters in a string are uppercase.
text = "HELLO"
result = text.isupper()
print(result)  # Output: True

# .isdigit():checks if all the characters in a string are digits (numeric characters).
number = "12345"
result = number.isdigit()
print(result)  # Output: True

列表相减

# 方法一
list1 = [5, 3, 8, 6]
list2 = [2, 1, 3, 4]

result = [x - y for x, y in zip(list1, list2)]
print(result)  # Output: [3, 2, 5, 2]

# 方法二
list1 = [5, 3, 8, 6]
list2 = [2, 1, 3, 4]

result = list(map(lambda x, y: x - y, list1, list2))
print(result)  # Output: [3, 2, 5, 2]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值