• 技术文章 >Python技术 >Python基础教程

    python check函数是什么

    小妮浅浅小妮浅浅2021-03-15 12:04:09原创15564

    在函数的使用上,有一种可以说是作为检验使用的了。因为它的返回值是按照正确计算的,所以我们在定义类的时候,经常会使用到它。下面再进行了函数的概念理解后,一起看看具体的实现方法吧。

    1、概念

    check函数基本上是用在自定义的类上,返回的值都是按照正确的去计算。

    2、实例

    自定义类的实现。

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    def check(x):

      

        if x+1 is 1+x:

      

            return False

      

        if x+2 is not 2+x:

      

            return False

      

        return True

      

    class Test(int):

      

        def __add__(self, v):

      

            if v == 1:

      

                return 0

      

            else:

      

                return v

      

    print(check(Test()))

    以上就是python check函数的介绍,想要返回值是正确的值,可以使用这个函数来解决。更多Python学习推荐:python教学

    (推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)

    专题推荐:python check
    上一篇:Python pop是什么 下一篇:python insert函数是什么

    相关文章推荐

    • python program是什么• python 基类是什么意思• python ctypes是什么• python中的class是什么• Python pop是什么

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网