python部落之python刷题宝之基础知识

any([True,False,True]), all([True,False,True])

any(iterable)->bool 迭代器对象中只要有一个为True,返回结果为True。

all(iterable)->bool 迭代器对象中都为True时,返回结果才为True。

Answer: True, False

isinstance(u'我‘,basestring)  
isinstance(object, classinfo)等同于java中的的 instanceOf.

isinstance(object, class-or-type-or-tuple) -> bool 
Return whether an object is an instance of a class or of a subclass thereof.  With a type as second argument, return whether that is the object's type.  The form using a tuple, isinstance(x, (A, B, ...)), is a shortcut for  isinstance(x, A) or isinstance(x, B) or ... (etc.).   
而basestring是str和unicode的超类(父类),也是抽象类,因此不能被调用和实例化,但可以被用来判断一个对象是否为str或者unicode的实例,isinstance(obj, basestring)等价于isinstance(obj, (str, unicode));
Answer: True

3

len(bin(5))
bin()函数用法 bin(number)-> string. 返回整型(integer)或长整型(long)的二进制表示,返回类型为字符串。

a = bin(5) print a 得到 a = '0b101'. '0b'表示二进制表示,‘101’为正数5的二进制表示。因为返回类型为string,故len()后得到为5.

Answer:5

表达式 callable(1) 的值为?
callable() 检查对象是否可用。 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.

5 cmp(2,3)

比较。 cmp(x,y)->integer. 如果x<y,返回-1,如果x==y,返回0,如果x>y,返回1.

6 complex(2,3)==complex('2+3j')

True。 complex()可以接受string对象。

7 dir(arg) 返回对应arg如class的变量和方法。

8 填空,如下表达式等价于(a//b, a%b)。 _(a,b)

Answer: divmod  divmod(x,y)-> (quotient,remainder) 返回元组。







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值