python对方法的迭代

欢迎关注我的博客Zhuhao's Blog获取最新文章

any()

Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to:
(返回True,如果iterable中的任何一个element是True。如果iterable是空的,返回False。等价与:)

def any(iterable):
    for element in iterable:
        if element:
            return True
    return False

对一个可迭代的对象,要想知道其中某一个元素是否符合某一个表达式,用 any(),最好不过了。

for

今天才知道,原来for循环还可以对方法进行循环,尽管之前就知道list中什么都可以放,可是放方法的还是头会见到,学习的路果然是任重而道远。

实际运用

问题:
You are given a string S.
Your task is to find out if the string S contains: alphanumeric characters, alphabetical characters, digits, lowercase and uppercase characters.

给你一个string S。
你的任务是判断string S是否包含: 数字字母都有 按字母表顺序(Unicode) 有数字 有小写字母 有大写字母

for method in [str.isalnum, str.isalpha, str.isdigit, str.islower, str.isupper]:
    print any(method(c) for c in s)

参考源

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值