zoukankan      html  css  js  c++  java
  • Python 中内置函数(一) abs、any和all

    abs()

    abs() 返回输的绝对值,输入为数字,若输入为负数,则返回负数的幅值。
    | 输入 | 输出
    | ---- | ---- | ----
    | abs(-3) | 3
    | abs(3+4j) | 5.0
    | abs("3") | TypeError

    all()

    all 输入为可迭代类型,如 list tuple 等,若 元素全为1 或 空 ,返回Ture ,否则 返回False.等价代码如下:

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

    | 输入 | 输出
    | ---- | ---- | ----
    | all([1,1,1]) | True
    | all([1,1,0]) | False
    | all(-3) | TypeError
    | all([]) | True

    any()

    all 输入为可迭代类型,如 list tuple 等,若 元素任意为真 ,返回Ture ;若为空 返回False.等价代码如下:

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

    | 输入 | 输出
    | ---- | ---- | ----
    | any([1,1,1]) | True
    | any([0,0,0]) | False
    | any(-3) | TypeError

  • 相关阅读:
    数据库部署
    css常见问题
    extjs记录
    C#相关问题
    window疑难问题解决
    常用linq
    不同数据库之间的相互链接
    聊天数据库
    无线路由接入
    [转]如何才能让你的简历被谷歌相中
  • 原文地址:https://www.cnblogs.com/Finding-bugs/p/14179704.html
Copyright © 2011-2022 走看看