callable(object)

中文说明:检查对象object是否可调用。如果返回True,object仍然可能调用失败;但如果返回False,调用对象ojbect绝对不会成功。

注意:类是可调用的,而类的实例实现了__call__()方法才可调用。

版本:该函数在python2.x版本中都可用。但是在python3.0版本中被移除,而在python3.2以后版本中被重新添加。

英文说明:Return True if the object argument appears callable, False if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed. Note that classes are callable (calling a class returns a new instance); class instances are callable if they have a __call__() method.

代码实例:

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
26
27
>>> callable(0)
False
>>> callable("mystring")
False
>>> def add(a, b):
…     return + b
>>> callable(add)
True
>>> class A:
…      def method(self):
…         return 0
>>> callable(A)
True
>>> a = A()
>>> callable(a)
False
>>> class B:
…     def __call__(self):
…         return 0
>>> callable(B)
True
>>> b = B()
>>> callable(b)
True

python callable 函数的更多相关文章

  1. python --- Python中的callable 函数

    python --- Python中的callable 函数 转自: http://archive.cnblogs.com/a/1798319/ Python中的callable 函数 callabl ...

  2. Python面向对象 -- slots, @property、多重继承MixIn、定制类(str, iter, getitem, getattr, call, callable函数,可调用对象)、元类(type, metaclass)

    面向对象设计中最基础的3个概念:数据封装.继承和多态 动态给class增加功能 正常情况下,当定义了一个class,然后创建了一个class的实例后,可以在程序运行的过程中给该实例绑定任何属性和方法, ...

  3. python 零散记录(六) callable 函数参数 作用域 递归

    callable()函数: 检查对象是否可调用,所谓可调用是指那些具有doc string的东西是可以调用的. 函数的参数变化,可变与不可变对象: 首先,数字 字符串 元组是不可变的,只能替换. 对以 ...

  4. python的函数

    函数一词起源于数学,但是在编程中的函数和数学中的有很大不同.编程中的函数式组织好的,可重复使用的,用于实现单一功能或相关联功能的代码块. 我们在学习过程中已经使用过一些python内建的函数,如pri ...

  5. python第六天 函数 python标准库实例大全

    今天学习第一模块的最后一课课程--函数: python的第一个函数: 1 def func1(): 2 print('第一个函数') 3 return 0 4 func1() 1 同时返回多种类型时, ...

  6. python之函数用法iter()

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法iter() #iter() #说明:对一个对象调用 iter() 就可以得到它的迭代 ...

  7. python基础,函数,面向对象,模块练习

    ---恢复内容开始--- python基础,函数,面向对象,模块练习 1,简述python中基本数据类型中表示False的数据有哪些? #  [] {} () None 0 2,位和字节的关系? # ...

  8. python常用函数拾零

    Python常用内置函数总结: 整理过程中参考了runoob网站中python内置函数的相关知识点,特此鸣谢!! 原文地址:http://www.runoob.com/python/python-bu ...

  9. Python一等函数

    一等对象 一等对象的定义: (1)在运行时创建 (2)能赋值给变量或数据结构中的元素 (3)能作为参数传给函数 (4)能作为函数的返回结果 ▲ Python中,整数.字符串和字典.函数都是一等对象. ...

随机推荐

  1. L4,an exciting trip

    expressions: a great number of 许多 in the centre of 在…的中部 sentences: I have just had breakfast. I hav ...

  2. jquery 事件注册 与重复事件处理

    <!doctype html><html lang="us"><head><meta charset="utf-8"& ...

  3. Pro/TOOLKIT入门教程汇总

    手把手教你开发Pro/TOOLKIT应用程序 手把手教你开发Pro/TOOLKIT应用程序(一) 手把手教你开发Pro/TOOLKIT应用程序(二) 手把手教你开发Pro/TOOLKIT应用程序(三) ...

  4. 转 spring security的使用

    [转自:http://haohaoxuexi.iteye.com/blog/2154714] 关于登录 目录 1.1     form-login元素介绍 1.1.1    使用自定义登录页面 1.1 ...

  5. 这丫头也的还真清楚,但是跑不通呢,换3.0.3的mybatis也不行

    http://java.dzone.com/articles/ibatis-mybatis-handling-joins http://mybatis.github.io/spring/mappers ...

  6. the.book.of.gimp.pdf文字不显示

    逆天了,不是中文也不显示. https://bugs.freedesktop.org/show_bug.cgi?id=70529 说要升级libfreetype,可是已经是wheezy最新了,其他不稳 ...

  7. 鉴客 C# 抓取页面(带认证)

    1. [代码][C#]代码     01 HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(""); 02 re ...

  8. JavaScript 面向对象(一)

    参考:http://www.iteye.com/topic/1123555

  9. javascript 用call来继承实例属性

    xxx.call(thisObj, arg1,...)的调用可以改变当前函数的执行环境为传入的thisObj对象.利用这一点可以实现继承————当前的对象获得XXX的属性和方法. 例子: functi ...

  10. mariadb cache

    Since MariaDB Galera cluster versions 5.5.40 and 10.0.14 you can use the query cache. Earlier versio ...